-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tutor.java
62 lines (51 loc) · 1.88 KB
/
Tutor.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Tutor {
String name;
String course;
String school;
int experience;
String contact;
// constructor method
public Tutor(String name, String course, String school, int experience, String contact) {
this.name = name;
this.course = course;
this.school = school;
this.experience = experience;
this.contact = contact;
}
public void work() {
System.out.println("My working is to teach...");
}
public void get_info() {
System.out.println("Name: " + name);
System.out.println("Course: " + course);
System.out.println("Experience: " + experience + " years");
System.out.println("Contact: " + contact);
}
// Method overload: get_info method with additional parameter
public void get_info(boolean includeSchool) {
get_info(); // Reuse the existing get_info method
if (includeSchool) {
System.out.println("School: " + school);
}
}
}
class TutorManager extends Tutor {
// constructor to instantiate the object
public TutorManager(String name, String course, String school, int experience, String contact) {
// We call the Tutor(parent) constructor args and pass the args to it
super(name, course, school, experience, contact);
}
// overridding the method work
public void work() {
// This method was defined earlier in the Tutor but now will be overidden
System.out.println("My work is to manage the tutors...");
}
public static void main(String[] args) {
// Creating an instance of tutor Manager
TutorManager tutorManager = new TutorManager("Mr Wamae", "Software Development", "UoN", 2,
"wamaejoseph392@gmail.com");
// calling the work() method
tutorManager.work();
// the above will print My work is to manage the tutors...
}
}