What is the order of intialization of variables in Java.

Showing Answers 1 - 10 of 10 Answers

Klasseic

  • Jun 12th, 2006
 

When an object is created, all its fields are set to default initial values for their respective types(zero for all numeric types, false for boolean, u000 for char, and null for object reference.)

Then the constructor is invoked. Each constructor has 3 phases.

  1. 1. Invoke a superclass's constructor
  2. 2.Initialize the fields using their initializers and any initialization blocks.
  3. 3.Execute the body of the constructor.

  Was this answer useful?  Yes

Class initialization takes place before any instance of the class can be created or a static method of the class can be invoked. A superclass is initialized before its subclasses are initialized. Initializing a class involves initialization of the static fields by executing their static initializer expressions and execution of any static initializer blocks.

  Was this answer useful?  Yes

sampra

  • Feb 15th, 2008
 

first of all declare a memory block according to data type
assign var name
initite by def valuew
assign orignal value

  Was this answer useful?  Yes

In Java the variable initialization should be in order.  The order is:


1. Static block variables initialize at first
2. Static method of variables initialize second
3. Static variables initialize third
4. Constructor variables initialize at fourth
5. and then Instance Variables initialize at last.


This is the way and order of initialization variables in Java.


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions