-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathAbstractClass.java
More file actions
40 lines (33 loc) · 887 Bytes
/
AbstractClass.java
File metadata and controls
40 lines (33 loc) · 887 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
package code;
abstract class Animal {
abstract void walk();
void breathe() {
System.out.println("This animal breathes air");
}
Animal() {
System.out.println("You are about to create an Animal.");
}
}
class Horse extends Animal {
Horse() {
System.out.println("Wow, you have created a Horse!");
}
void walk() { //subclass has to implement the base class abstract method.
System.out.println("Horse walks on 4 legs");
}
}
class Chicken extends Animal {
Chicken() {
System.out.println("Wow, you have created a Chicken!");
}
void walk() {
System.out.println("Chicken walks on 2 legs");
}
}
public class AbstractClass {
public static void main(String args[]) {
Horse horse = new Horse();
horse.walk();
horse.breathe();
}
}