一些方法只是被声明,而没有实现
没有方法体
前面用 abstract 关键字修饰
1.2 注意
不能被声明为private、static、final
1.3 实例
package com.geek99.demo;
public class Test {
public static void main(String[] args) {
Cat cat = new Cat();
cat.run();
Dog dog = new Dog();
dog.run();
}
}
abstract class Animal
{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public abstract void run();
//private abstract void m1();
//public abstract static void m2();
//public final abstract void m3();
}
class Dog extends Animal{
@Override
public void run() {
System.out.println("Dog run...");
}
}
class Cat extends Animal{
@Override
public void run() {
System.out.println("Cat run...");
}
}
原文出处:http://geek99.com/node/421#
该博客教程视频地址:http://geek99.com/node/1617