JAVA类和对象的问题

2025-03-03 19:31:55
推荐回答(4个)
回答1:

Student类中的computer是其一个属性,computer这个属性既不是int型也不是string 型,而是一个对象型。而这个对象是类Computer的一个实例。Computer类不是Student的子类,而应该是Computer类是Student的一部分。是is part of 关系。

回答2:

Student 中的computer只是对象 Student的成员变量,他是一个引用,指向Computer对象,就像C中的指针一样

回答3:

你可以这样理解:computer是一个对象,student也是一个对象,同时student又拥有computer,所以当然要在student中声明computer了。

回答4:

相当于computer是Student的成员属性。