-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimals.java
More file actions
51 lines (40 loc) · 944 Bytes
/
Animals.java
File metadata and controls
51 lines (40 loc) · 944 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
41
42
43
package Com.learning.Week8;
public class Animals {
public Animals(){
}
public void animalSounds(){
System.out.println("The animal makes a sound");
}
}
class Pigs extends Animals{
public Pigs(){
super();
}
public void animalSounds(){
System.out.println("Pigs oink");
}
}
class Cats extends Animals{
public Cats(){
super();
}
public void animalSounds() {
System.out.println("cats meow");
}
public void animalSounds(int num) {
for (int count = 1; count <= num; ) {
System.out.println("The cat meowed");
count++;
}
System.out.println("The cat has meowed "+ num +" times");
}
}
class Test{
public static void main(String[] args) {
Cats cat = new Cats();
Pigs pig = new Pigs();
cat.animalSounds();
cat.animalSounds(2);
pig.animalSounds();
}
}