01-面向对象(继承-概述).avi

 1 package myFirstCode;
 2  /*
 3 将学生和工人的共性描述提取出来,单独进行描述,
 4 只要让学生和工人与单独描述的这个类有关系,就可以了。
 5 
 6 继承:
 7 1. 提高了代码的复用性
 8 2. 继承让类与类之间产生了关系,有了这个关系,才有了多态的特性。
 9 
10 注意:千万不要为了获取其他类的功能,简化代码而继承。
11 必须是类与类之间有所属关系才可以继承。所属关系 is a。谁是谁中的一员。
12 */
13 
14 class Person
15 {
16     String name;
17     int age;
18     
19 }
20 
21 class Student extends Person
22 {
23     void study()
24     {
25         System.out.println("good study");
26     }
27 }
28 
29 class Worker extends Person
30 {
31     void work()
32     {
33         System.out.println("good work");
34     }
35 }
36 
37 class ExtendsDemo {
38 
39     public static void main(String[] args) {
40         // TODO Auto-generated method stub
41 
42     }
43 
44 }
View Code

相关文章:

  • 2021-12-12
  • 2021-10-04
  • 2021-12-17
  • 2021-08-18
  • 2022-01-15
  • 2022-02-28
  • 2022-12-23
  • 2021-05-12
猜你喜欢
  • 2022-01-16
  • 2021-08-12
  • 2022-12-23
  • 2021-09-04
  • 2021-11-05
  • 2021-10-05
  • 2021-07-22
相关资源
相似解决方案