+ 1
whats wrong?
interface game{ String name; String type; int MAXamountOfPlayers; boolean onlineGame; void openGame(); game(String name , String type , int MAXamountOfPlayers , boolean onlineGame){ this.name = name; this.type= type; this.MAXamountOfPlayers = MAXamountOfPlayers; this.onlineGame = onlineGame; } } public class Main implements game { public static void main(String[] args) { game("cod" , "shooting" , 100 , true); System.out.println (game); openGame(); } @Override public void openGame(){ System.out.println ("Opening Game..."); } }
6 Answers
+ 1
ClassName obj = new ClassName();
Here new ClassName() is the object and obj is the reference variable pointing to that object.
Some good practices-
1) class name should start with an upper case letter. Eg- class Game{ }
2) variable names should follow camel case. Eg- maxAmountOfPlayers.
3) camel case would apply for methods as well. Eg- openGame();
I have modified your code. It might take a little time to sink in but you will get there eventually. Just read and practice more.
https://code.sololearn.com/c3g0225iQGSy/?ref=app
0
yahel interface cannot have a constructor. Why? because it is not a class. So you cannot create an instance of it. The class implementing the interface must provide all the details.
0
Avinesh đđŒđđ» , what does "instance" mean in java?
0
It is nothing but an object of the class. Instead of using an interface you can replace it with an abstract class which would make things easier.
0
Can you give me an example for object of class?
0
Avinesh alright, thanks!