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
Auf dieser Seite können Sie das Online-Video Instance initializer block in java in hindi mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Tarun Sir 11 August 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,195 Mal angesehen und es wurde von 26 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!