/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class TestStaticInnerClass
{
private int prop1 = 5;
private static int prop2 = 9;
static class StaticInnerClass
{
private static int age;
public void accessOuterProp()
{
//下面代码出现错误:静态内部类无法访问外部类的实例成员
System.out.println(prop1);
//下面代码正常
System.out.println(prop2);
}
}
}
/*
TestStaticInnerClass.java:22: 错误: 无法从静态上下文中引用非静态 变量 prop1
System.out.println(prop1);
^
1 个错误
请按任意键继续. . .
*/
静态内部类无法访问外部类的实例成员
最新推荐文章于 2021-04-27 15:06:07 发布