forked from SadeeshaJayaweera/Java-Practical-Codes-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.java
More file actions
31 lines (27 loc) · 679 Bytes
/
Copy pathAnimal.java
File metadata and controls
31 lines (27 loc) · 679 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
/*
This is the Question No 10 Part two - Example code for Abstract classes and methods
the object code is Animal_Main.java
*/
// Abstract class Animal
public abstract class Animal {
// Abstract method without implementation
abstract void makeSound();
// Concrete method with implementation
void sleep() {
System.out.println("Zzzz...");
}
}
// Subclass Dog inheriting from Animal
class Dog extends Animal {
@Override
void makeSound() {
System.out.println("Woof Woof!");
}
}
// Subclass Cat inheriting from Animal
class Cat extends Animal {
@Override
void makeSound() {
System.out.println("Meow Meow!");
}
}