51,397
社区成员




class Computer {
String brand;
int cpuspeed;
}
class Student {
Computer com;
}
public class Test2{
public static void main(String[] args) {
Computer c = new Computer();
c.brand = "Lenovo";
c.cpuspeed = 99;
Student s = new Student();
s.com = c;
System.out.println(s.com.brand);
System.out.println(s.com.cpuspeed);
}
}
[/quote]
在没有创建对象之前s之前,他们有关系吗。 我就是搞不懂Computer com这句代码有什么用class Computer {
String brand;
int cpuspeed;
}
class Student {
Computer com;
}
public class Test2{
public static void main(String[] args) {
Computer c = new Computer();
c.brand = "Lenovo";
c.cpuspeed = 99;
Student s = new Student();
s.com = c;
System.out.println(s.com.brand);
System.out.println(s.com.cpuspeed);
}
}
[/quote]
class student 这里面的Computer com的Computer跟class Comouter有关吗??class Computer {
String brand;
int cpuspeed;
}
class Student {
Computer com;
}
public class Test2{
public static void main(String[] args) {
Computer c = new Computer();
c.brand = "Lenovo";
c.cpuspeed = 99;
Student s = new Student();
s.com = c;
System.out.println(s.com.brand);
System.out.println(s.com.cpuspeed);
}
}