1. 程式人生 > >抽象類不能被例項化

抽象類不能被例項化

/**
 * 
 */
package test919;

public abstract class Animal {
	private String name;
	
	public Animal(String name) {
		super();
		this.name = name;
	}
	
	public abstract void enjoy();
}
package test919;

public class Cat extends Animal {
	private String eyeColor;
	
	public Cat(String name,String c) {
		super(name);
		eyeColor = c;
	}

	@Override
	public void enjoy() {
		System.out.println("123");

	}
	
	public static void main(String[] args) {
		Cat c = new Cat("smallred", "red");
		System.out.println(c.eyeColor);
		c.enjoy();
	}

}

結果: