i wants to ask about the difference between the use of the "new" kewword:
EX:
Code :Student s=new Student();
and the composition, for example:
Code :public class Proffessor{ Student advisee; //an attribute //details omitted
Printable View
i wants to ask about the difference between the use of the "new" kewword:
EX:
Code :Student s=new Student();
and the composition, for example:
Code :public class Proffessor{ Student advisee; //an attribute //details omitted
The keyword "new" actually tells the JVM to allocate memory and instantiate a new object. This object can then be used through your variable.
When you dont call new and just create a variable the JVM automatically assigns the value of null to that variable unless its a primitive. This means you have a variable to play with but if you try to invoke any methods on that variable without having a proper object assigned to it you will get a NullPointerException.
// Json
thanks alot