Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

A simple question on inner class!

syberboysyberboy Member Posts: 9
Hi!
I got the code as following!
But I met a compile error at line of "/*****ERROR*****/
Teach me how to rewrite this line, please!
Thanks!

public class InnerInnerTest { public static void main(String s[]) { new Outer().new Inner().new InnerInner().new InnerInnerInner().doSomething(); new Outer().new InnerChild().doSomething(); new Outer2().new Inner2().new InnerInner2().doSomething();/*****ERROR*****/ new InnerChild2().doSomething(); } } class Outer { String name = "Vel"; class Inner { String name = "Sharmi"; class InnerInner { class InnerInnerInner { public void doSomething() { System.out.println(name); System.out.println(Outer.this.name); System.out.println(Inner.this.name); } } } } class InnerChild extends Inner { public void doSomething() { System.out.println(Outer.this.name); System.out.println(super.name); System.out.println(this.name); } } } class Outer2 { static String name = "Vel"; static class Inner2 { static String name = "Sharmi"; class InnerInner2 { public void doSomething() { System.out.println(name); System.out.println(Outer2.name); } } } } class InnerChild2 extends Outer2.Inner2 { public void doSomething() { System.out.println(name); System.out.println(Outer2.name); System.out.println(super.name); System.out.println(this.name); } } SyberBoyCN
Sign In or Register to comment.