Skip to content

Commit e5bade6

Browse files
committed
Added Files
1 parent 32c840e commit e5bade6

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public void speak() {
2+
System.out.println("Human speaking");
3+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
class Monkey {
3+
public void jump() {
4+
System.out.println("Monkey juming");
5+
}
6+
7+
public void bite() {
8+
System.out.println("Monkey biting");
9+
}
10+
}
11+
interface BasicAnimal {
12+
void Sleep();
13+
void Eat();
14+
}
15+
16+
class Human extends Monkey implements BasicAnimal {
17+
18+
public void speak() {
19+
System.out.println("Human speaking");
20+
}
21+
22+
@Override
23+
public void Sleep() {
24+
System.out.println("Human sleeping");
25+
}
26+
27+
@Override
28+
public void Eat() {
29+
System.out.println("Human eating");
30+
}
31+
}
32+
33+
public class testHuman {
34+
public static void main(String[] args) {
35+
Human human = new Human();
36+
human.speak();
37+
human.jump();
38+
human.bite();
39+
human.Sleep();
40+
human.Eat(); // Polymorphism in action. Monkey's methods are overridden in Human class.
41+
Monkey m = new Human();
42+
43+
m.bite(); // Monkey calls this method when the user requests a bite
44+
}
45+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
abstract class Pen {
2+
abstract void write();
3+
abstract void refill();
4+
5+
}
6+
class FountainPen extends Pen {
7+
void write() {
8+
System.out.println("Writing on fountain pen");
9+
}
10+
void refill() {
11+
System.out.println("Refilling fountain pen");
12+
}
13+
void changeNib() {
14+
System.out.println("Changing Nib");
15+
}
16+
17+
}
18+
19+
public class testPen {
20+
public static void main(String[] args) {
21+
FountainPen pen = new FountainPen() ;
22+
pen.changeNib();
23+
pen.write();
24+
}
25+
}

0 commit comments

Comments
 (0)