class Person {
String name = "jack";
int age = 28;
void show() {
System.out.println(name + "---" + age);
}
public static class PersonDemo {
public static void main(String[] args) {
people(new Person());
new Person().age=9;//没有意义的 立即销毁
Person p = new Person();
p.show();
p.name = "劳务";
p.show();
}
}
public static void people(Person P) {
P.age = 15;
P.name = "laoshu";
P.show();
}
}
匿名内部类
class Inner {
void show() {
System.out.println("inner demo");
}
}
class Outter {
public void function() {
new Inner() {//创建Inner 的子类对象 这就是匿名内部类
void show() {
System.out.println("outter demo");
}
}.show();
}
}
abstract class Inner {
abstract void show();
}
class Outter {
public void function() {
new Inner() {//创建抽象类的子类匿名对象
void show() {
System.out.println("outter demo");
}
};
}