Instance initializer block in java in hindi

Published: 11 August 2021
on channel: Tarun Sir
1,195
26

In this video you will learn about instance initializer block in java.

As static initializer block can be used to initialize static fields in a named class, java provides ability to initialize the instance variables during object creation using instance initializer block.
Primarily, instance initializer block serve the same purpose as constructor during the object creation.
Instance initializer block is executed before the execution of the constructor. An instance initializer block is executed exactly once for every object created.
A class can have any number of instance initializer blocks and they are executed in the order, in which they are defined.
this keyword and super keyword can be used in the instance initializer block.
Instance initializer block can be used for common initialization code that will be executed regardless of which constructor is executed for object creation.

public class DemoInitializerBlock
{ { System.out.println("This is the initializer block1");//Will be executed first for every object created
}
public DemoInitializerBlock(){System.out.println("Object Created");}
public static void main(String[]args)
{ DemoInitializerBlock d1=new DemoInitializerBlock ();
DemoInitializerBlock d2=new DemoInitializerBlock ();
}
}
#java #tarunsir #learnprogramming #initializerblock


On this page of the site you can watch the video online Instance initializer block in java in hindi with a duration of hours minute second in good quality, which was uploaded by the user Tarun Sir 11 August 2021, share the link with friends and acquaintances, this video has already been watched 1,195 times on youtube and it was liked by 26 viewers. Enjoy your viewing!