-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface & Inheritance
More file actions
71 lines (50 loc) · 1.5 KB
/
Copy pathInterface & Inheritance
File metadata and controls
71 lines (50 loc) · 1.5 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
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
63
64
65
66
67
68
69
package taoshiflex.lab7;
public class Student {
int age;
// Constructor
public Student(int age) {
this.age = age;
}
// Display method
void display() {
System.out.println("Student Age: " + age);
}
}
package taoshiflex.lab7;
// TeachingAssistant class inherits from Student and implements Employee
class TeachingAssistant extends Student implements Employee {
int id;
String name;
int salary;
// Constructor
public TeachingAssistant(int age, int id, String name, int salary) {
super(age); // Call to Student constructor
this.id = id;
this.name = name;
this.salary = salary;
}
@Override
public void display() {
// Override and provide implementation for both Student and Employee details
System.out.println("Teaching Assistant Details:");
System.out.println("Age: " + age);
System.out.println("ID: " + id);
System.out.println("Name: " + name);
System.out.println("Salary: " + salary);
}
}
package taoshiflex.lab7;
// 1. Interface Employee
interface Employee {
int designation = 0; // Default variable (implicitly public static final)
void display(); // Abstract method
}
package taoshiflex.lab7;
public class Lab7 {
public static void main(String[] args) {
// Create a TeachingAssistant object
TeachingAssistant ta = new TeachingAssistant(20, 101, "Taoshif", 400000);
// Call display method
ta.display();
}
}