Hi
I have been looking another post where I came across a code...
I jsut added a superclass to it....
I am unable to unerstand the output sequence...
class zion
{
String temp=getString();
zion()
{
System.out.println("In zions constructor");
}
static String getString()
{
System.out.println("getstring");
return "string returned";
}
}
class Animal2 extends zion{
int i=InitialValue();
String name;
Animal2(String name){ super(); this.name=name; }
static{ System.out.println(" C's static" ); }
Animal2()
{ this(makeRandomName()); System.out.println("this"); }
static String makeRandomName(){
System.out.println("static");
int x=(int)(Math.random()*5);
String name=new String[]{"Fluffy","Fido","Rover","Spike","Gidi"}[x];
//System.out.println(name);
return name; }
public int InitialValue(){
System.out.println("Initial");
return 0; }
public static void main(String... args){
Animal2 a=new Animal2();
System.out.println(a.name);
Animal2 b=new Animal2("Zeus");
System.out.println(b.name);
}}
Output:
C's static
static
getstring
In zions constructor
Initial
this
Fluffy
getstring
In zions constructor
Initial
Zeus
I am unable to find how this output sequence came....
Please somebody help me to understand this..
Thanks
Praveen SP