踽踽行
2015-04-27 21:34
//外部类
public class HelloWorld {
// 外部类中的静态变量score
private static int score = 84;
// 创建静态内部类
public static class SInner {
// 内部类中的变量score
int score = 91;
public static void show() {
System.out.println("访问外部类中的score:" + HelloWorld.score );
System.out.println("访问内部类中的score:" + this.score);
}
}
// 测试静态内部类
public static void main(String[] args) {
// 直接创建内部类的对象
SInner si=new SInner();
// 调用show方法
si.show();
}
}
静态方法只属于当前类而不属于对象所以静态方法中不存在当前对象,因而不能使用“this”,当然也不能使用”super”;
Java入门第二季
531385 学习 · 6328 问题
相似问题