package 测试标识符;
class Computer{// 放前面,电脑类型
String brand;
}
public class Student {
//void play() ;
int age;
String name;
int xuehao;
Computer comp;// 取名字
public static void main(String[] args) {
Student stu = new Student();
stu.age=23;
stu.name="唐";
stu.xuehao=15408;
Computer com = new Computer();//为另一个类建立对象
com.brand="lenovo";//另一个类赋值
stu.comp= com;//com的信息赋给stu,再调用
stu.play();
}
void play() {
System.out.println("我在学习,用的电脑是:"+comp.brand);
}
}
类与类的嵌套
最新推荐文章于 2023-12-24 11:21:25 发布