Inner

Java nested classes 嵌套类

你。 提交于 2019-12-04 17:03:06
quoted from : http://tutorials.jenkov.com/java/nested-classes.html; http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html nested classes: 1.static nested classes: public class Outer{ public class Nested{ } } declare inner class: Outer.Nested instance = new Outer.Nested(); 2.Non-static nested classes(Inner Classes): public class Outer{ private String text = "I am a string!"; public class Inner{ public void printText() { System.out.println(text); } } } ① declaration;② call the printText() method; Outer outer = new Outer(); Outer.Inner inner = new Outer.Inner(); inner.printText();