-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHackerrankJava0053.java
47 lines (36 loc) · 1.35 KB
/
HackerrankJava0053.java
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
public class HackerrankJava0053 {
public static void main(String[] args) {
// Java Method Overriding
// https://www.hackerrank.com/challenges/java-method-overriding/problem?isFullScreen=true
Sports c1 = new Sports();
Soccer c2 = new Soccer();
System.out.println(c1.getName());
c1.getNumberOfTeamMembers();
System.out.println(c2.getName());
c2.getNumberOfTeamMembers();
}
}
class Sports {
String getName() {
return "Generic Sports";
}
void getNumberOfTeamMembers() {
System.out.println("Each team has n players in " + getName());
}
}
class Soccer extends Sports {
@Override
String getName() {
return "Soccer Class";
}
// -------------------------------------------------------------------------------------------------
// --- You need to add this lines for solution hackerrank provides all other lines for challange ---
// -------------------------------------------------------------------------------------------------
@Override
void getNumberOfTeamMembers() {
System.out.println("Each team has 11 players in " + getName());
}
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
}