We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bbe2881 commit 8050004Copy full SHA for 8050004
1 file changed
OverloadingAndOverriding.java
@@ -0,0 +1,30 @@
1
+package com.company;
2
+class Overloading{
3
+ int multiply(int a, int b) {
4
+ return a * b;
5
+ }
6
+
7
+ int multiply(int a, int b, int c) {
8
+ return a * b * c;
9
10
11
+}
12
+public class OverloadingAndOverriding extends Overloading {
13
14
15
+ return a * b + 10; // Overriding the method
16
17
+ public static void main(String[] args) {
18
19
+ Overloading obj1 = new Overloading();
20
+ Overloading obj2 = new OverloadingAndOverriding();
21
22
+ // Overloading (compile time)
23
+ System.out.println(obj1.multiply(2, 3)); // 6
24
+ System.out.println(obj1.multiply(2, 3, 4)); // 24
25
26
+ // Overriding (runtime)
27
+ System.out.println(obj2.multiply(2, 3)); // 16
28
29
30
0 commit comments