-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolymorphism.java
More file actions
39 lines (33 loc) · 903 Bytes
/
Polymorphism.java
File metadata and controls
39 lines (33 loc) · 903 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
public class Polymorphism {
public static void main(String[] args) {
// Deer d = new Deer();
// d.eat();
// Calculator calc = new Calculator();
// System.out.println(calc.sum(1,2));
// System.out.println(calc.sum((float)1.5,(float)2.5));
// System.out.println(calc.sum(1,2, 3));
}
}
//Function overriding(Run time polymorphism)(Dynamic)
// class Animal {
// void eat() {
// System.out.println("eats anything");
// }
// }
// class Deer extends Animal {
// void eat() {
// System.out.println("eats grass");
// }
// }
//Function overloading(Compile time polymorphism)(Static)
// class Calculator {
// int sum(int a,int b) {
// return a+b;
// }
// float sum(float a,float b) {
// return a+b;
// }
// int sum(int a, int b, int c) {
// return a+b+c;
// }
// }