Hi all,
While preparing for SCJp1.4,i was going thru a study guide, which has listed out some important points.I had some doubts regarding two rules and tried to develop an example code based on that rule.I got different output plz help on the following two doubts:
1.Overloading, Overriding, Runtime Type and Object Orientation
-If a call to the super class constructor is made with argument i.e for example with the following prototype,
super(ArgList);
Here the ArgList can be static variables or static methods belonging to the given class or one of its super class.
� ArgList cannot refer to instance variables or instance methods belonging to the given class or to one of its super class.
Now i tested the above rule by the following example , but this example is contradicting this rule, please look carefully into the code and compare it with the rule.
class Super{
Super(){} //no-arg constructor
Super(int i){ //one-arg constructor
System.out.println(i);
System.out.println("super");
}
}
public class
Test extends Super{
int k=3; //no-static instance variable
Test(){} //no-arg constructor
Test(int a){ //one-arg constructor
super(a);
System.out.println("sub");}
public static void main(
String a[]){
Test t = new Test();
Test t1 = new Test(t.k);
}
}//end of sub class
OUTPUT- 3, super, sub
2.Declarations and Access control
-While equating array reference variables if the dimensions aren�t appropriate then compile time error is not caused but runtime error sets in.
But the following example of mine gives compiler error "incomparable types"
public class Test2{
Test2 a[] = new Test2[4];
Test2 b[][]= new Test2[2][];
public static void main(String a[]) {
Test2 t = new Test2();
if(t.a == t.b);
System.out.println("true");
}
}
Please clear my doubts.