抽象類不能被例項化
阿新 • • 發佈:2018-12-10
/**
*
*/
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(); } }
結果: