抽象类

为什么要有抽象类?

  因为父类方法有不确定性,我们在Animal中定义了一个方法,但是它会被子类的方法覆盖掉,我们就不知道这个方法原本是做什么的

 1 public class test1 
 2 {
 3     public static void main(String[] args) {
 4     }
 5 }
 6 
 7 class Animal
 8 {
 9     String name;
10     int age;
11     
12     //动物会叫
13     public void cry()
14     {
15         System.out.println("不知道怎么叫");
16         //问题是这个方法永远都不会用到
17     }
18 }
不会被用到的父类方法

相关文章:

  • 2021-10-31
  • 2021-06-18
  • 2021-12-10
  • 2021-07-19
  • 2021-10-28
  • 2021-10-28
  • 2021-10-18
  • 2022-02-23
猜你喜欢
  • 2021-12-17
  • 2021-11-05
  • 2021-07-01
  • 2021-06-28
  • 2021-10-03
  • 2022-01-20
  • 2021-10-26
相关资源
相似解决方案