Hi Firoj,
If you want to exectue super class first the following format
class Super {
static {
System.out.println("Static Block in Super");
}
{
System.out.println("Instance Block in Super");
}
}
class Sub extends Super{
{
System.out.println("Instance block in Sub");
}
static {
System.out.println("Static block in Sub");
}
public static void main(
String []arg){
Super s = new Super();
System.out.println("Main in Sub");
}
}
Output:
Static Block in Super
Static block in Sub
Instance Block in Super
Main in Sub
Otherwise you want to exectue sub class first the following format
class Super {
static {
System.out.println("Static Block in Super");
}
{
System.out.println("Instance Block in Super");
}
}
class Sub extends Super{
{
System.out.println("Instance block in Sub");
}
static {
System.out.println("Static block in Sub");
}
public static void main(String []arg){
Sub s = new Sub ();
System.out.println("Main in Sub");
}
}
Output:
Static Block in Super
Static block in Sub
Instance Block in Super
Instance block in Sub
Main in Sub
Thanks&Regards,
Dhaya