|
@@ -0,0 +1,106 @@
|
|
|
+package com.lovecoding.day13.inner01;
|
|
|
+
|
|
|
+public class Out {
|
|
|
+ //外部类的属性
|
|
|
+ private String a = "a";
|
|
|
+ private String b = "b";
|
|
|
+ private static String c = "c";
|
|
|
+ private static String d = "d";
|
|
|
+
|
|
|
+ //静态内部类
|
|
|
+ static class InterStatic extends A implements B {
|
|
|
+ private String a = "a";
|
|
|
+ private static String c = "c";
|
|
|
+
|
|
|
+ //方法
|
|
|
+ public void interShow1(){
|
|
|
+ //System.out.println(b); //静态不能访问非静态
|
|
|
+ System.out.println(a);
|
|
|
+ System.out.println(Out.c); //区分
|
|
|
+ System.out.println(InterStatic.c); //类名.
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void interShow2(){
|
|
|
+ System.out.println(Out.d); //区分
|
|
|
+ System.out.println(InterStatic.c); //类名.
|
|
|
+ //System.out.println(a); //静态不能访问非静态
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void a() {}
|
|
|
+ @Override
|
|
|
+ public void b() {}
|
|
|
+ }
|
|
|
+
|
|
|
+ //非静态的
|
|
|
+ class InterNotStatic extends A implements B {
|
|
|
+ private String a = "a";
|
|
|
+ private static String c = "c";
|
|
|
+
|
|
|
+ //方法
|
|
|
+ public void interShow1(){
|
|
|
+ System.out.println(b);
|
|
|
+ System.out.println(a);
|
|
|
+ System.out.println(Out.c); //区分
|
|
|
+ System.out.println(InterStatic.c); //类名.
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void interShow2(){
|
|
|
+ System.out.println(Out.d); //区分
|
|
|
+ System.out.println(InterStatic.c); //类名.
|
|
|
+ //System.out.println(a); //静态不能访问非静态
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void a() {}
|
|
|
+ @Override
|
|
|
+ public void b() {}
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //外部方法
|
|
|
+ public void OutMethod01(){
|
|
|
+ //属性
|
|
|
+ System.out.println(InterStatic.c); //静态直接访问
|
|
|
+ InterStatic interStatic = new InterStatic();
|
|
|
+ System.out.println(interStatic.a);
|
|
|
+
|
|
|
+ //方法
|
|
|
+ InterStatic.interShow2(); //静态直接访问
|
|
|
+ interStatic.interShow1(); //对象
|
|
|
+
|
|
|
+ //非静态 用对象
|
|
|
+ InterNotStatic interNotStatic = new InterNotStatic();
|
|
|
+ interNotStatic.interShow1();//对象
|
|
|
+
|
|
|
+ InterNotStatic.interShow2(); ////静态直接访问
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //外部静态方法
|
|
|
+ public static void OutMethod02(){
|
|
|
+ //访问静态的
|
|
|
+ InterNotStatic.interShow2();
|
|
|
+ System.out.println(InterNotStatic.c);
|
|
|
+
|
|
|
+ InterStatic.interShow2();
|
|
|
+ System.out.println(InterStatic.c);
|
|
|
+
|
|
|
+ //new 外部类().new 内部类();
|
|
|
+ InterNotStatic interNotStatic = new Out().new InterNotStatic();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public InterNotStatic getInterNotStatic(){
|
|
|
+ //通过方法返回
|
|
|
+ return new Out().new InterNotStatic();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+abstract class A{
|
|
|
+ public abstract void a();
|
|
|
+}
|
|
|
+
|
|
|
+interface B{
|
|
|
+ public abstract void b();
|
|
|
+}
|