-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprelims.java
More file actions
35 lines (30 loc) · 740 Bytes
/
Copy pathprelims.java
File metadata and controls
35 lines (30 loc) · 740 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
// Dexter G. Inguito
// Parent class
class Animal {
public void makeSound() {
System.out.println("The animal makes a sound.");
}
}
// Subclass
class Cat extends Animal {
@Override
public void makeSound() {
System.out.println("The cat meows.");
}
public void quarrel() {
System.out.println("The cat is quarreling.");
}
}
public class prelims {
public static void main(String[] args) {
// Create an Animal object
Animal animal = new Animal();
animal.makeSound();
// Create a Cat object
Cat cat = new Cat();
cat.makeSound();
cat.quarrel();
Animal catAsAnimal = new Cat();
catAsAnimal.makeSound();
}
}