當我編譯,我得到一個錯誤信息說視頻有望構造函數參數「不爭論」多態性:構造不會接受參數
import java.util.*;
abstract class Thing
{
}
class Video extends Thing
{
String description;
int price;
String title;
void Video (String d , int p, String t)
{
this.description = d;
this.price = p;
this.title = t;
}
String getDescription()
{
return description;
}
}
class BookOnTape extends Thing
{
String description;
void BookOnTape (String d)
{
description = d;
}
String getDescription()
{
return description;
}
}
class Funiture extends Thing
{
String description;
void Furniture (String d)
{
description = d;
}
String getDescription()
{
return description;
}
}
public class Lookup
{
/*private static HashMap<Thing, Integer> rentalList;
static
{
rentalList = new HashMap<Thing, Integer>();
rentalList.put(new Video(5), new Integer(0));
}*/
public static void main(String args[])
{
System.out.println("fart");
Thing farmer = new Video("fgfg", 5, "gfgf");
}
}
當我編譯如下:
class A
{
}
class B extends A
{
String name;
B (String n)
{
this.name = n;
}
}
class TestPoly
{
public static void main(String args[])
{
A poly = new B("test");
}
}
它工作正常。我沒有看到區別。這裏有什麼不對嗎?...