+ 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..."); } }

28th May 2020, 3:18 PM
Yahel
Yahel - avatar
6 odpowiedzi
+ 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
28th May 2020, 3:54 PM
Avinesh
Avinesh - avatar
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.
28th May 2020, 3:29 PM
Avinesh
Avinesh - avatar
0
Avinesh 🙏🏼👍🏻 , what does "instance" mean in java?
28th May 2020, 3:33 PM
Yahel
Yahel - avatar
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.
28th May 2020, 3:36 PM
Avinesh
Avinesh - avatar
0
Can you give me an example for object of class?
28th May 2020, 3:46 PM
Yahel
Yahel - avatar
0
Avinesh alright, thanks!
28th May 2020, 4:29 PM
Yahel
Yahel - avatar