-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloading.java
More file actions
33 lines (28 loc) · 875 Bytes
/
Overloading.java
File metadata and controls
33 lines (28 loc) · 875 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
class Parent {
// Overloaded method
public void display() {
System.out.println("Parent's display method");
}
}
class Child extends Parent {
// Overriding method
@Override
public void display() {
System.out.println("Child's display method");
}
// Overloaded method
public void display(String message) {
System.out.println("Child's overloaded display method: " + message);
}
}
public class Main {
public static void main(String[] args) {
Parent parent = new Parent();
Child child = new Child();
// Method overriding
parent.display(); // Output: Parent's display method
child.display(); // Output: Child's display method
// Method overloading
child.display("Hello!"); // Output: Child's overloaded display method: Hello!
}
}