-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodOverriding2.java
More file actions
46 lines (35 loc) · 872 Bytes
/
Copy pathMethodOverriding2.java
File metadata and controls
46 lines (35 loc) · 872 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
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Question:
Use the super keyword to call
the parent class method.
Output:
Hello I am a motorcycle, I am a cycle with an engine.
My ancestor is a cycle who is a vehicle with pedals.
*/
class Bicycle {
// Parent class method
String define_me() {
return "a vehicle with pedals.";
}
}
class Motorcycle extends Bicycle {
// Child class method
String define_me() {
return "a cycle with an engine.";
}
Motorcycle() {
// Call parent class method using super
System.out.println(
"Hello I am a motorcycle, I am " + define_me()
);
System.out.println(
"My ancestor is a cycle who is " + super.define_me()
);
}
}
class Solution {
public static void main(String[] args) {
// Create Motorcycle object
Motorcycle M = new Motorcycle();
}
}