Java Object Creation in Static Block | Java Tutorial Videos

This Java Tutorial Videos “Java Object Creation in Static Block” providing example codes used to explain how to create object inside static block and assign object address to local variable and static variable.


Object Creation in Static Block:

  • We can create object inside any static member of Java class.
  • In the previous examples, we have seen that how to create object inside main method.
  • Here we are providing examples to create object inside static block and assign address to either local variable or static variable.
  • Local variable can be accessed only within the block or method.
  • Static variable can be accessed anywhere using Class-name.

 

Create Object inside static block and assign address to Local variable:

 

Create Object inside static block and assign address to Static variable:

 

Share this