-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4.java
More file actions
51 lines (39 loc) · 866 Bytes
/
Q4.java
File metadata and controls
51 lines (39 loc) · 866 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
44
45
46
47
48
49
50
51
package CodingChalange;
abstract class Animal {
String name;
Animal(String name)
{
this.name = name;
}
abstract void makeSound();
}
class Dog extends Animal{
Dog(String name)
{
super(name);
}
void makeSound(){
System.out.println("BOW BOW BOW....");
}
}
class Cat extends Animal{
Cat(String name)
{
super(name);
}
void makeSound()
{
System.out.println("Meouwww Meouwww.....");
}
}
public class Q4 {
public static void main(String[] args) {
Dog d1 = new Dog("Booby");
d1.makeSound();
System.out.println(d1.name);
System.out.println("--------------");
Cat c1 = new Cat("Simba");
c1.makeSound();
System.out.println(c1.name);
}
}