-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppolymorphism.java
54 lines (39 loc) · 948 Bytes
/
ppolymorphism.java
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
class animal{
void soundProduce(){
System.out.println("animal produce sound.");
}
}
class Dog extends animal{
@Override
void soundProduce(){
super.soundProduce();
System.out.println("dog bark");
}
}
class cat extends animal{
@Override
void soundProduce(){
System.out.println("cat meow meow");
}
}
class calculator{
public int add(int num1,int num2){
return num1+num2;
}
public double add(double num1, double num2){
return num1+num2;
}
}
public class ppolymorphism {
public static void main(String[] args) {
animal b = new animal();
Dog a = new Dog();
a.soundProduce();
b.soundProduce();
calculator x= new calculator();
double c = x.add(4.5, 4.5);
int m = x.add(1,50);
System.out.println(m);
System.out.println(c);
}
}