-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.java
More file actions
62 lines (54 loc) · 1.12 KB
/
Inheritance.java
File metadata and controls
62 lines (54 loc) · 1.12 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class Inheritance {
public static void main(String[] args) {
Fish nemo = new Fish();
nemo.eats();
nemo.swim();
Bird Hok = new Bird();
Hok.breaths();
Hok.fly();
// Dog dobby = new Dog();
// dobby.eats();
// dobby.legs = 4;
// System.out.println(dobby.legs);
// Fish shark = new Fish();
// shark.eats();
}
}
//base class
class Animal {
String color;
void eats() {
System.out.println("eats");
}
void breaths(){
System.out.println("breaths");
}
}
class Mammal extends Animal {
// int legs;
void walk() {
System.out.println("walks");
}
}
class Fish extends Animal {
// int legs;
void swim() {
System.out.println("swim");
}
}
class Bird extends Animal {
// int legs;
void fly() {
System.out.println("fly");
}
}
// class Dog extends Mammal {
// String breed;
// }
//drived class / subclass
// class Fish extends Animal {
// int fins;
// void swim() {
// System.out.println("swims in water");
// }
// }