Non static Members in Java |  Core Java Concepts

This Core Java Concepts “Non static Members in Java” post is giving definitions and basic introduction to all the non static members of java application including variable, block, constructor and user defined method.


 

Non static variable:

  • Declaration of variable inside the class and outside to methods & blocks.
  • It is not recommended to initialize non static variable directly
  • for example a non static variable in bank application (consider accno) cannot be decided by programmer.
  • Non static variable also called instance variable.
  • In the process of Object creation, these variables initializes with default values.

 

Constructor:

  • Special java method.
  • Constructor name & Class name should be same.
  • Return type is not allowed.
  • Used to initialize non-static(instance) variables.
  • We need to call constructor explicitly in the process of object creation.

 

Non-static block:

  • Defining a block with no identity.
  • We can’t access explicitly.
  • JVM invokes implicitly as soon as object has created.

 

Non static user method:

  • Block of instructions having identity.
  • Method takes input, process input and generates output.
  • Must be called explicitly using its name.
  • We can access non static method using object address.

 

Share this