-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamplePolymorphismSwingSword_main.java
More file actions
18 lines (17 loc) · 1.25 KB
/
ExamplePolymorphismSwingSword_main.java
File metadata and controls
18 lines (17 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class ExamplePolymorphismSwingSword_main {
// method overloading - methods with same name but different signatures (parameters passed)
// method overriding - inherit method and override it, parent and child have method with same name and signature, child overrides the parents, see inheritance example
public static void main(String args[]) {
ExamplePolymorphismSwingSword player = new ExamplePolymorphismSwingSword();
player.SwingSword(); // call the method expecting no parameters
player.SwingSword("lightning"); // call the method expecting a string parameter
player.SwingSword("fire"); // call the method expecting a string parameter
player.SwingSword("poison"); // call the method expecting a string parameter
player.SwingSword(0); // call the method expecting an integer parameter
player.SwingSword(10); // call the method expecting an integer parameter
player.SwingSword(-10); // call the method expecting an integer parameter
player.SwingSword("lightning", 10); // call the method expecting a string and an integer parameter
player.SwingSword("lightning", 15); // call the method expecting a string and an integer parameter
player.SwingSword("poison", -5); // call the method expecting a string and an integer parameter
}
}