-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.java
More file actions
60 lines (48 loc) · 1.24 KB
/
Program.java
File metadata and controls
60 lines (48 loc) · 1.24 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
class Animal {
private String name;
private int age;
public Animal(String name, int age){
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void makeSound() {
System.out.println("Some generic animal sound");
}
}
class Dog extends Animal {
private String breed;
public Dog(String name, int age, String breed){
super(name, age);
this.breed = breed;
}
public String getBreed() {
return breed;
}
public void makeSound() {
System.out.println("Dog barks");
}
}
class Cat extends Animal {
private boolean isIndoor;
public Cat(String name, int age, boolean isIndoor){
super(name, age);
this.isIndoor = isIndoor;
}
public boolean isIndoor() {
return isIndoor;
}
}
public class Program{
public static void main(String[] args){
Dog d = new Dog("Bob", 3, "Labrador");
Cat c = new Cat("Whiskers", 2, true);
d.makeSound(); // Outputs: Dog barks
c.makeSound(); // Outputs: Some generic animal sound
}
}