-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodOverloadingAndOverriding.java
More file actions
56 lines (40 loc) · 1.55 KB
/
Copy pathMethodOverloadingAndOverriding.java
File metadata and controls
56 lines (40 loc) · 1.55 KB
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
import java.util.Scanner;
class Python {
void hello() {
System.out.println("Hello From Python Class");
}
}
class DotNet extends Python {
void hello() {
System.out.println("Hello From Dotnet Class");
}
}
class AirthmeticOverloading {
public void multiply(int a, int b) {
System.out.println("Multiplication of two entered integer numbers gives us: " + (a * b));
}
public void multiply(double a, double b) {
System.out.println("Multiplication of two entered decimal numbers gives us: " + (a * b));
}
}
public class MethodOverloadingAndOverriding {
public static void main(String[] args) {
AirthmeticOverloading airthmeticOverloading = new AirthmeticOverloading();
Python p = new Python();
DotNet m = new DotNet();
Python ref; // refrence object of python class
ref = p; //refrence points to the python object
ref.hello(); // calling the hello function present in python class
ref = m; // refrence points to the dotnet object
ref.hello(); // calling the hello function present in dotnet calss
Scanner sc = new Scanner(System.in);
System.out.println("\nEnter any two integer values for multiplication: ");
int a = sc.nextInt();
int b = sc.nextInt();
airthmeticOverloading.multiply(a, b);
System.out.println("\nEnter any two decimal values for multiplication: ");
double da = sc.nextDouble();
double db = sc.nextDouble();
airthmeticOverloading.multiply(da, db);
}
}