内部类不能通过直接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]