内部类如何实例化
程序员文章站
2022-05-23 17:33:18
...
内部类不能通过直接new的方式生成实例,而是要通过其外部类的实例来生成实例
关键点:[color=red]Home home = student.new Home("南京路100号");[/color]
public class Student {
private String name;
public Student(){}
public Student(String name){
this.name = name;
}
public class Home {
private String address;
public Home(){}
public Home(String address){
this.address = address;
}
}
public static void main(String[] args) throws IOException {
Student student = new Student("张三");
Home home = student.new Home("南京路100号");
}
}
关键点:[color=red]Home home = student.new Home("南京路100号");[/color]
上一篇: spring中两种创建容器的方式和三种获取bean的方式
下一篇: 扩展实例对象访问内部属性问题