We can split these as three cases :
First case :: class Bird {
{ System.out.print("bl "); }
public Bird() { System.out.print("b2 "); }
}
class Raptor extends Bird {
static { System.out.print("r1 "); }
public Raptor() { System.out.print("r2 "); }
{ System.out.print("r3 "); }
static { System.out.print("r4 "); }
}
class Hawk extends Raptor
{
public static void main(String[] args) {
System.out.print("pre ");
System.out.println("hawk ");
}
}
OutPut r1 r4 pre hawk
Second Case::: class Bird {
{
System.out.print("bl ");
}
public Bird() { System.out.print("b2 "); }
}
class Raptor extends Bird {
static {
System.out.print("r1 ");
}
public Raptor() { System.out.print("r2 "); }
{ System.out.print("r3 "); }
static { System.out.print("r4 "); }
}
class Hawk extends Raptor
{
public static void main(String[] args) {
System.out.print("pre ");
new Hawk();
System.out.println("hawk ");
}
}
output :: r1 r4 pre bl b2 r3 r2 hawk
Third case ::: class Bird {
{
System.out.print("bl ");
}
public Bird() { System.out.print("b2 "); }
}
class Raptor extends Bird {
static {
System.out.print("r1 ");
}
public Raptor() { System.out.print("r2 "); }
{ System.out.print("r3 "); }
static { System.out.print("r4 "); }
}
class Hawk
{
public static void main(String[] args) {
System.out.print("pre ");
new Raptor ();
System.out.println("hawk ");
}
}
Output :::
pre r1 r4 bl b2 r3 r2 hawk
