Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 测试继承的构造函数时出现类型不匹配错误_Java_Oop_Abstract Class_Subclass - Fatal编程技术网

Java 测试继承的构造函数时出现类型不匹配错误

Java 测试继承的构造函数时出现类型不匹配错误,java,oop,abstract-class,subclass,Java,Oop,Abstract Class,Subclass,我正在使用eclipse。当我尝试使用Junit测试一个类时,我在尝试创建一个对象时遇到了一个错误 public abstract class Property { private int number = 0; private String street = null; private String city = null; private String postCode = null; private int numberOfRooms =

我正在使用eclipse。当我尝试使用Junit测试一个类时,我在尝试创建一个对象时遇到了一个错误

    public abstract class Property {

    private int number = 0;
    private String street = null;
    private String city = null;
    private String postCode = null;
    private int numberOfRooms = 0;

    public Property(int number, String street, String city, String postCode, int numberOfRooms) {...}
    ...
}

这是junit测试文件:

public class PropertyTest {

@Test
    public void testHouse() {
        Property house = new House(1, "Percy Road", "London", "WC2N 5DU", 2);
        assertEquals("1 Percy Road, London WC2N 5DU (2 bedroom house)", house.toString());
    }
}
我在PropertyTest中遇到了这个错误:类型不匹配:无法将房屋转换为房产。
据我所知,此代码应该可以工作

什么包是
属性
?你确定导入了正确的类吗?它们都在同一个包中。我刚刚删除了测试文件并从头创建了另一个,现在它可以工作了。我不知道为什么我以前没试过。ThanksSide注意:除非您真的想测试您的toString实现,否则请避免编写此类测试。如果要测试对象的内容,请使用getter。问题可能是导入错误的
属性的import语句错误。
public class PropertyTest {

@Test
    public void testHouse() {
        Property house = new House(1, "Percy Road", "London", "WC2N 5DU", 2);
        assertEquals("1 Percy Road, London WC2N 5DU (2 bedroom house)", house.toString());
    }
}