public class Test2 {
static class TestClass1 {
int x = 1;
String test() {
return "1";
}
}
static class TestClass2 extends TestClass1 {
int x = 2;
String test() {
return "2";
}
}
static class TestClass3 extends TestClass2 {
int x = 3;
int testX() {
return ((TestClass1)this).x;
}
String test() {
return super.test();
}
}
public static void main(String[] args) {
TestClass3 obj = new TestClass3();
System.out.println(obj.testX());
System.out.println(obj.test());
}
}
It produces expected output
1
2
The point is that there is no way to call test() method of TestClass1 class!
super.super.test()
won't compile but
((TestClass1)this).test()
will produce java.lang.StackOverflowError.
Despite on we can access superclass members of any level by casting this to appropriate class (see The Java Language Specification at http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.11.2), polymorphism allows us to access immediate superclass only, not overridden methods of higher levels (see The Java Language Specification at http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12.4.9).
4 comments:
Bonjour I'd love to thank you for such a terrific made site!
I was sure this is a perfect way to introduce myself!
Sincerely,
Monte Phil
if you're ever bored check out my site!
[url=http://www.partyopedia.com/articles/cinderella-party-supplies.html]cinderella Party Supplies[/url].
Guy
You have got to see this. Obama playing on XBox. Funniest video ever. http://bit.ly/bllhx1
aefefeaf Ccomctpapuftjoqzpgjr, Penis Enlargement Pills sdfsdfswe Penis Enlargement, VuuIOeQ, [url=http://www.buypenisenlargement.com/]Penis Enlargement[/url] fwaefefef. ynaytanyt penis enlargement, bbQrETC, [url=http://www.male-sexual-styles.com]penis enlargement[/url] lrutsltk This is good information that will help others. srjyzent penis enlargement pills, bRgGALs srjyzent penis enlargement bRgGALs, [url=http://penisenlargementkey.com]penis enlargement[/url] rthnBDtTEG jhdjhd~
zxyzxqwert Male enhancement pills reviews that realy works to enhance you sexual health and improve sed drive and stamina. read review at http://www.male-sexual.com penis enlargement methods - penis enhancement - asdaQdasdDSHRdshsd penis enlargement zxyqwertzx
Post a Comment