Having a little trouble understanding objects (Java) -
i trying understand difference between:
public class guessgame { player p1; player p2; player p3;
and
public void startgame() { p1 = new player(); p2 = new player(); p3 = new player();
basically, these both in program? understand startgame method creating objects, first part of program for?
first part calling declaration of object.
declarations notify compiler using name refer variable type type. declarations not instantiate objects. instantiate player
object, or other object, use new operator.
the second part called instantiating object
the new
operator instantiates new object allocating memory it. new requires single argument: constructor method object created. constructor method responsible initializing new object.
you can check official java tutorial on object creation more info. or here.
Comments
Post a Comment