package com.hisoft.java.DifferentClass;
/**
* 静态内部类就是在成员内部类前加上static修饰符
* 静态成员内部是可以访问外部类静态属性和方法
*/
public class StaticOutClass {
String outValue;
static String name;
static class MyStaticInnerClass {
String inValue;
// 静态内部类中可以定义静态变量以及静态方法
static int i = 100;
public void testInner() {
System.out.println("this is testInner() "+name);
System.out.println("this is testInner() ");
run();
}
}
public static void run(){
System.out.println("this is myouter Run()");
}
public static int run1(){
return 1;
}
public void testOuter() {
System.out.println("this is testOuter!");
MyStaticInnerClass myinner1 = new MyStaticInnerClass();
MyStaticInnerClass myinner2 = new MyStaticInnerClass();
System.out.println(myinner1.i);
myinner2.i=130;
System.out.println(myinner1.i);
}
public static void main(String[] args) {
StaticOutClass so =new StaticOutClass();
so.testOuter();
}
}
静态内部类
最新推荐文章于 2024-09-06 09:49:19 发布