Which of the following is false for Static Initializers?

Options
- A static initializer block resembles a method with a name, arguments, and return type
- They need to be referred from outside the class definition.
- The code in a static initializer block is executed by the virtual machine when the class is loaded.
- Both a and b


CORRECT ANSWER : Both a and b

Discussion Board
Static Initializers

Static initializer blocks is used to initialize static variables when the class is loaded. The code used in these static initializer blocks are quite complex depending on the kind of output a person is looking for. The block resembles a method having no name, no arguments and no return type as there is no need of it to be referred from outside the class definition. The code is usually executed by the virtual machine when the class is loaded.

It is similar to the constructor where the block cannot contain a return statement so it doesn't require a return type. Having parameters are not necessary as it is loaded when the class is loaded so it doesn't have an argument list.

Rohit Sharma 08-7-2014 08:37 AM

validate given answer

it should be - The code in a static initializer block is executed by the virtual machine when the class is loaded

vineeta 11-24-2013 12:00 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement