Java new keyword
r1 = new MCA2();
r2 = new MCA2();
r3 = new MCA2();
- It is used to create the object.
- It allocates the memory at runtime.
- It invokes the object constructor.
- We can also use the new keyword to create the array object.
- How to create a single object?
- Syntax:
- Example:
- How to create multiple objects?
- Syntax:
- Example:
r1 = new MCA2();
r2 = new MCA2();
r3 = new MCA2();
- How to create arrays of objects?
- Array which store values like string, integer, Boolean, etc.
- Array of objects stores objects.
- The array elements store the location of reference variables of the object
- Syntax:
- Example:
Full Example:
Tags:
Core java