有两节课:
人
/**
* This class models a person.
*
* @author author name
* @version 1.0.0
*/
public class Person {
/* Name of the person */
private String name;
/* Address of the person */
private String address;
/**
* Constructs a <code>Person</code> object.
*
* @param initialName the name of the person.
* @param initialAddress the address of the person.
*/
public Person (String initialName, String initialAddress) {
name = initialName;
address = initialAddress;
}
/**
* Returns the name of this person.
*
* @return the name of this person.
*/
public String getName() {
return this.name;
}
/**
* Returns the address of this person.
*
* @return the address of this person.
*/
public String getAddress() {
return this.address;
}
}
员工是一个人,因此每个Employee对象也是一个Person对象。因此,可以将Employee参考变量分配给Person参考变量。
人员人员=新员工(“乔·史密斯”,“大街100号”,3000.0);
但是也可以将其分配给Employee参考变量吗?
雇员雇员=新雇员(“乔·史密斯”,“主大街100号”,3000.0);
如果是,那么两者之间有什么区别。我想掌握引用和分配变量的想法,因此我非常感谢您进行澄清。
当年话下
慕森王
MMMHUHU
相关分类