怎样在打印语句中打印这3个i变量?

nineteen73 2013-09-03 03:02:58
怎样在打印语句中打印这3个i变量?
class x {
int i = 1;
class y {
int i = 2;
void func() {
int i = 3;
System.out.println( ? );
}
}
}

...全文
211 8 打赏 收藏 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyace 2014-03-20
  • 打赏
  • 举报
回复
引用 4 楼 fudongrifdr 的回复:
public class Test {

	public static void main(String[] args) {
		X xxx = new X();
		X.Y y = xxx.new Y();
		y.func();

	}

}

class X {
	int i = 1;

	class Y {
		int i = 2;

		void func() {
			int i = 3;
			System.out.println(X.this.i);
			System.out.println(this.i);
			System.out.println(i);
		}
	}
}
真能通过?我编译时候在X xxx = new X();这行出现: No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).
nineteen73 2013-09-03
  • 打赏
  • 举报
回复
成功了耶!多谢多谢!!!
末日哥 2013-09-03
  • 打赏
  • 举报
回复
引用 5 楼 nineteen73 的回复:
是的,编译通过了,但是不知道怎么打印这三个i变量,而且是类中套类
试试我写的那个
nineteen73 2013-09-03
  • 打赏
  • 举报
回复
是的,编译通过了,但是不知道怎么打印这三个i变量,而且是类中套类
末日哥 2013-09-03
  • 打赏
  • 举报
回复
public class Test {

	public static void main(String[] args) {
		X xxx = new X();
		X.Y y = xxx.new Y();
		y.func();

	}

}

class X {
	int i = 1;

	class Y {
		int i = 2;

		void func() {
			int i = 3;
			System.out.println(X.this.i);
			System.out.println(this.i);
			System.out.println(i);
		}
	}
}
fenglren 2013-09-03
  • 打赏
  • 举报
回复
引用 2 楼 nineteen73 的回复:
这个是在main方法里的 public class Test { public static void main(String[] args){ class A { int x = 1; class B { int x = 2; void func() { int x = 3; System.out.println( ); } } } } } 这样 呢
你确定这样编译能通过?
nineteen73 2013-09-03
  • 打赏
  • 举报
回复
这个是在main方法里的 public class Test { public static void main(String[] args){ class A { int x = 1; class B { int x = 2; void func() { int x = 3; System.out.println( ); } } } } } 这样 呢
tony4geek 2013-09-03
  • 打赏
  • 举报
回复
没有main 方法/

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧