-2

I've been trying to find it online but nothing is helping me.

I have a coin flip class and a main class. I want to use the coin flip class inside my main method but all I get is errors. I've seen that you need both files in a package, then import it but that doesn't work.

import Game.CoinFlip;

package Game;

public class Main {

    public static void main(String[] args) {
        coinFlip();
    }
}

There are redlines under the main class and package saying "'class' or 'interface' expected". The import statement is also grey.

All help is much appreciated.

2 Answers2

0

First off, is the coin flip class in the same package as the main? If not then change the type of class of coin flip to public, then try to hover over coinflip() and click on import class

Madtasmo
  • 21
  • 5
0

try to replace this

import Game.CoinFlip;
package Game;

with

package Game;
import Game.CoinFlip;

be sure the import path is valid. Can you show the project structure?

Importing packages in Java ,

https://beginnersbook.com/2013/03/packages-in-java/ may help you

John
  • 446
  • 6
  • 16