We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3259b8f commit b22e191Copy full SHA for b22e191
PolymorphismDemo1.java
@@ -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
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