类 class
对象 object(instance)
属性 field
class Computer {
String brand; //品牌
}
public class classAndInstance {
// field
int id;
String sname;
int age;
Computer comp;
void study() {
System.out.println("我正在学习!使用我们的电脑,"+comp.brand);
}
classAndInstance() {
}
public static void main(String[] args) {
classAndInstance stu1 = new classAndInstance();
stu1.sname = "张三";
Computer comp1 = new Computer();
comp1.brand = "DELL";
stu1.comp = comp1;
stu1.study();
}
}