-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleInheritanceFootballer.java
More file actions
28 lines (27 loc) · 1.47 KB
/
ExampleInheritanceFootballer.java
File metadata and controls
28 lines (27 loc) · 1.47 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
public class ExampleInheritanceFootballer { // parent class, super class, inheritance can be chained (child will get great parents methods etc), final class cannot be inherited, abstract class must be inherited
public ExampleInheritanceFootballer() { // constructors are not inherited but can be called by the child / subclasses via "super()" in their constructor, cannot be hidden or overridden
System.out.println("=== Footballer Constructor ==="); // even though the constructors are not inherited, the default constructor will always run, "super()" will always run
}
public ExampleInheritanceFootballer(int x) { // constructor expecting an integer parameter passed
System.out.println("=== Footballer Parameter Constructor ===");
}
public String testInherit = "### Footballer Inherited ###"; // data member will be inherited
public void Select() { // we will override this inherited method in the child classes / subclasses
System.out.println("~~~ Unknown Player Selected ~~~");
}
public void Run() { // method will be inherited
System.out.println("Run Method");
}
public void Pass() { // method will be inherited
System.out.println("Pass Method");
}
public void Shoot() { // method will be inherited
System.out.println("Shoot Method");
}
private void PrivateTest() { // this method cannot be inherited due to the private access modifier
System.out.println("Test");
}
public void Position(String x) {
System.out.println("Position " + x);
}
}