Skip to content

Commit b22e191

Browse files
committed
Polymorphism demo 1
1 parent 3259b8f commit b22e191

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

PolymorphismDemo1.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//Type of polymorphism
2+
//1. static - overloading
3+
//2. Duynamic - overriding
4+
class PolymorphismDemo1{
5+
6+
public static int add(int a,int b){
7+
return a+b;
8+
}
9+
//overloading by changing number of parameters
10+
public static int add(int a,int b,int c){
11+
return a+b+c;
12+
}
13+
//overloading by changing datatype
14+
public static float add(float a, float b){
15+
return a+b;
16+
}
17+
public static void main(String[] args){
18+
System.out.println(add(1,2));
19+
System.out.println(add(1,2,3));
20+
System.out.println(add(1.0f,2.3f));
21+
System.out.println(add(1,2.3f));//automatic type casting / type promotion
22+
}
23+
}

0 commit comments

Comments
 (0)