+ 1
What is The "new" keyword in Java? i am confused.
please help me as a friend, Thank You Very Much
3 Respuestas
+ 4
The new operator instantiate a class by allocating memory for a new object and returning a reference to that memory. The new operator also invoke object constructor. The new operator returns a reference to the object it created. This reference assigned to the variable of the appropriate type like:
A ob = new A();
While using new keyword some points to be remember :
The new keyword is followed by a class name and passing values to the constructors.
Number of arguments to the constructors must be the same in signature of constructor.
The type of variable on the left side of assignment is compatible with the class being instantiated.
+ 3
allocates a space in the memory and initialize the object.
+ 1
thanks dude