package cn.bjsxt.oop;
public class Computer {
String brand;
int cpuSpeed;
}
package cn.bjsxt.oop;
public class Student {
//静态的数据
String name;
int id; //学号
int age;
String gender;
int weight;
Computer computer;
//动态的行为
public void study(){
System.out.println(name+"在學習");
}
public void sayHello(String sname){
System.out.println(name+"向"+sname+"說:你好!");
}
}
package cn.bjsxt.oop;
public class Test2 {
public static void main(String[] args) {
Student s1 = new Student();
s1.name = "高琪";
s1.age = 18;
Computer c = new Computer();
c.brand = "联想";
c.cpuSpeed = 100;
s1.computer = c;
c.brand = "戴尔";
System.out.println(s1.computer.brand);
}
}
内存分析: