-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoopspolymorphism.java
More file actions
61 lines (53 loc) · 861 Bytes
/
oopspolymorphism.java
File metadata and controls
61 lines (53 loc) · 861 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
52
53
54
55
56
57
58
59
//compile time polymorphism
class Calculator
{
int add(int a,int b)
{
return a+b;
}
double add(double a,double b)
{
return a+b;
}
}
public class Main
{
public static void main(String[] args)
{
Calculator c=new Calculator();
System.out.println(c.add(10,20));
System.out.println(c.add(5.5,4.5));
}
}
//runtime polymorphism
class Vehicle
{
void start()
{
System.out.println("vehicle");
}
}
class Car extends Vehicle
{
void start()
{
System.out.println("car");
}
}
class Bike extends Vehicle
{
void start()
{
System.out.println("bike");
}
}
public class Main
{
public static void main(String[] args)
{
Vehicle v1=new Car();
Vehicle v2=new Bike();
v1.start();
v2.start();
}
}