我正在尝试编译:
Property flat = new Flat(1, "Street", "City", "BDK 8DN", 2, 1);
属性是一个抽象类,而Flat是一个子类。
public class Flat extends Property
Flat包含Property中的所有抽象方法。
我在Property上有警告,在新Flat()上有错误
无法从公寓转换为物业
对泛型类型Property的引用应参数化
编辑
额外的代码:
属性
public abstract class Property {
private int number;
private String street;
private String city;
private String postCode;
private int numberOfRooms;
protected Map<Room, ITenant> rooms = new HashMap<Room, ITenant>();
public Property(int number, String street, String city, String postCode, int numberOfRooms) {
super();
this.number = number;
this.street = street;
this.city = city;
this.postCode = postCode;
this.numberOfRooms = numberOfRooms;
}
public abstract String displayOccupiedProperty();
public abstract boolean isAvailable();
public abstract void occupyRoom(Room room, ITenant tenant);
}
平面
public class Flat extends Property {
private int floor;
public Flat(int number, String street, String city, String postCode, int numberOfRooms, int floor) {
super(number, street, city, postCode, numberOfRooms);
this.floor = floor;
}
屋
public class House extends Property {
public House(int number, String street, String city, String postCode, int numberOfRooms) {
super(number, street, city, postCode, numberOfRooms);
}
测试文件
public class PropertyTest {
@Test
public void testFlat() {
Property flat = new Flat(1, "Street", "City", "BDK 8DN", 2, 1);
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。