Java - Non-static Block

Ratish, Arya


Outline: Non-static block: *Any code written between two curly brackets; *Executed for each object that is created; *Executes before constructor's execution; *Can initialize instance member variables of the class; *Create a class named NonStaticTest; *Create a non-static block and a constructor inside it; *Check the output; *Include multiple non-static blocks; *they will be executed in the sequence in which they appear in the class; *Check the output; *Non-static block is not a substitute for constructor. Pre-requisite: Java - Using this Keyword

Published by:

Spoken Tutorial IIT Bombay

DOER Persistent Identifier: