抽象类还是个类,只不过不能有对象
package Abstract_;
//某些方法需要声明但是还没确定如何实现,就声明为抽象方法
public class Abstract01 {
public static void main(String[] args) {
// new Animal("sad");//抽象类不能被实例化(不能造对象)
}
}
abstract class Animal{
private String name;
public Animal(String name) {
this.name = name;
}
//eat这个方法不知道具体应该实现什么功能,就设置为抽象方法(没有方法体)
//抽象方法等着子类去实现
public abstract void eat();
}
class cat extends Animal{
public cat(String name) {
super(name);
}
//父类的抽象方法必须在子类里面实现
@Override
public void eat() {
System.out.println();
}
}
//抽象类里面可以没有抽象方法,可以有普通方法
abstract class haha{
}
package Abstract_;
public class exer {
public static void main(String[] args) {
Manager manager = new Manager("小张",5624,5678.99,2000);
manager.work();
}
}
abstract class Employee{
private String name;
private int id;
private double salary;
public Employee(String name, int id, double salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public abstract void work();
}
class Manager extends Employee{
private double bonus;
public Manager(String name, int id, double salary, double bonus) {
super(name, id, salary);
this.bonus = bonus;
}
@Override//子类重写父类的抽象方法
public void work() {
System.out.println("经理"+ getName()+"工作中。。。");
}
}