Java program to initialize instance data member using instance initializer block
belongs to collection: Java Instance Initializer Block Programs
All Answers
total answers (1)
belongs to collection: Java Instance Initializer Block Programs
total answers (1)
In this program, we will create a class that contains an Instance Initializer Block, which is used to initialize Instance data members.
Program/Source Code:
The source code to initialize Instance Data Member using Instance Initializer Block is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two classes Sample and Main. The Sample class contains an instance member num, and Instance Initializer Block to initialize data members. It also contains a constructor.