package theChildOfGod.bjxy.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 + "说:同志你辛苦了!");
}
public void play(String sname) {
System.out.println(name + "向" + sname + "说:我在海底世界玩的好开心呀!");
}
}
package theChildOfGod.bjxy.oop;
public class Computer {
String brand;
int cpuSpeed;
}
package theChildOfGod.bjxy.oop;
public class test02 {
public static void main(String[] args) {
Student s1 = new Student();
s1.name = "徐子峰";
s1.age = 20;
s1.gender = "boy";
s1.id = 110;
s1.weight = 120;
s1.study();
s1.sayHello("江晴");
Student s2 = new Student();
s2.name = "江晴";
s2.sayHello("徐子峰");
s2.play("徐子峰");
Computer c = new Computer();
c.brand = "戴尔";
c.cpuSpeed = 100;
s1.computer = c;
Computer c2 = new Computer();
c2.brand = "surface";
c2.cpuSpeed = 110;
s2.computer = c2;
System.out.println(s1.name + "的电脑品牌是" +s1.computer.brand);
System.out.println("cpu速度是" +s1.computer.cpuSpeed);
System.out.println(s2.name + "的电脑品牌是" +s2.computer.brand);
System.out.println("cpu速度是" +s2.computer.cpuSpeed);
}
}
程序运行过程内存分析02
最新推荐文章于 2018-12-18 17:54:25 发布