abstract使用的注意点:
-
1.abstract不能用来修饰:属性、构造器等结构
-
2.abstract不能用来修饰私有方法、静态方法、final方法、final的类
package com.atguigu.com;
public class AbstractTest {
public static void main(String[] args) {
//Cannot instantiate the type Person,抽象的不可实例化
// Person p1 = new Person();
// p1.eat();
}
}
abstract class Creature{
abstract public void breath();
}
abstract class Person extends Creature{
String name;
int age;
//不是抽象方法
// public void eat() {
//
// }
//抽象方法
public abstract void eat();
public void walk() {
System.out.println(“人走路”);
}
public Person() {
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
class Student extends Person{
public Student(String name, int age) {
super(name,age);
}
@Override
public void eat() {
// TODO Auto-generated method stub
System.out.println(“学生多吃有营养的”);
}
//父类的父类也要重写
@Override