-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson5_6.java
More file actions
45 lines (40 loc) · 897 Bytes
/
Lesson5_6.java
File metadata and controls
45 lines (40 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
抽象類: 用abstract 關鍵字聲明的類稱為抽象類,很多具有相同特徵和
行為的對象可以抽象為一個類,很多具有相同特徵和行為的類可以抽象為一個抽象類(無法實體化)
*/
public class Lesson5_6{
public static void main(String[] args){
Man man = new Man();
man.move();
man.eat();
Woman w = new Woman();
w.move();
w.eat();
}
}
abstract class Animals{
public abstract void move();//方法的聲明,抽象方法只有聲明,沒有實現
}
abstract class Person extends Animals{
public abstract void eat();
public void sleep(){
System.out.println("我是sleep");
}
}
//繼承抽象類的具體類必須實現所有抽象方法
class Man extends Person{
public void move(){
System.out.println("我是man 跑");
}
public void eat(){
System.out.println("我是man 吃");
}
}
class Woman extends Person{
public void move(){
System.out.println("我是Woman 逛");
}
public void eat(){
System.out.println("我是Woman 吃");
}
}