可能重複:
What is the use of creating a constructor for an abstract class in Java?抽象類中構造函數的用法是什麼?
例子:
abstract public class AbstractDemo
{
private int ab;
public AbstractDemo()
{
ab=10;
}
public int getAb()
{
return ab;
}
public void abstractMethod()
{
//On the line below it gives error.
AbstractDemo demo=new AbstractDemo();
}
}
編輯,以格式代碼
希望它是重複的問題,我問這個已經[鏈接] http://stackoverflow.com/questions/5404168/constructors-in-abstract-classes – developer 2011-03-30 06:18:47
HTTP:// stackoverflow.com/questions/504977/why-cant-i-create-an-abstract-constructor-on-an-abstract-c-class – 2011-03-30 06:19:17
這是一個確切的重複?問題是他直接抽象基類的實例化。事實上,它甚至不像提及的問題一樣的語言! – 2011-03-30 06:27:04