我怎樣才能改變這種實現:如何保護類直接實例化
public interface Animal()
{
public void eat();
}
public class Dog implements Animal
{
public void eat()
{}
}
public void main()
{
// Animal can be instantiated like this:
Animal dog = new Dog();
// But I dont want the user to create an instance like this, how can I prevent this declaration?
Dog anotherDog = new Dog();
}
修正刪除__()__從__implements動物(){__即改變**實現動物(){**它**實現動物{** – Visruth