Object Creation in Main Method | Core Java Training Videos
This Core Java Training Videos “Object Creation in Main Method ” explains clearly how to create object for a class inside main method to access non static members of java application.
- A pre-defined keyword in java.
- It is also called ‘new’ operator.
- It allocates object memory in Heap area.
- All the non static variables get memory inside object and initializes with default values.
- As soon as object has created, JVM invokes non static block implicitly.
- Constructor executes right after non static block.
Object creation in java
int a ; // non-static variable
public static void main(String args)
new Test(); // object creation
- Also called class members.
- Can access using class name.
- Static block executes implicitly at the time of class loading.
- Static variable get memory in JVM method area.
- Static variable initializes with default values at the time of class loading.
- Also called object members.
- Can access using object reference.
- Non Static block executes implicitly at the time of object creation.
- Instance variable get memory allocation inside JVM heap memory.
- Non static variable initializes with default value at the time of object creation.