1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| public class InnerClassTest { public static void main(String[] args) { Person.Dog dog = new Person.Dog(); dog.show();
Person p = new Person(); Person.Bird bird = p.new Bird(); bird.sing(); System.out.println(); bird.display("黄鹂"); } }
class Person{ String name = "小明"; int age; public void eat(){ System.out.println("人:吃饭"); } static class Dog{ String name; int age; public void show(){ System.out.println("卡拉是条狗");
} } class Bird{ String name = "杜鹃"; public Bird(){ } public void sing(){ System.out.println("我是一只小小鸟"); Person.this.eat(); eat(); System.out.println(age); } public void display(String name){ System.out.println(name); System.out.println(this.name); System.out.println(Person.this.name); } } public void method(){ class AA{ } } { class BB{ } } public Person(){ class CC{ } } }
|