public class New {
String data = "super" ;
void method() {
System.out.println("method of super");
System.out.println(data);
}
}
class SubNew extends New {
String data = "sub" ;
void method() {
System.out.println("method of sub");
System.out.println(data);
}
public static void main(String manal[]) {
New nn = new New();
SubNew ss = new SubNew();
New ns = new SubNew();
System.out.println("************** nn ***********");
nn.method();
System.out.println("************** ss ***********");
ss.method();
System.out.println("************** ns ***********");
ns.method();
}
}
The outpout of this prog. is ..
************** nn ***********
method of super
super
************** ss ***********
method of sub
sub
************** ns ***********
method of sub
sub
Can anyone please Explain me why after calling ns.method(); it is using data of SubNew when we r using a
reference of New class ...
Thanks ...
Manal