-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2p3.java
More file actions
53 lines (43 loc) · 1.25 KB
/
Assignment2p3.java
File metadata and controls
53 lines (43 loc) · 1.25 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
abstract class Person {
String name;
int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
abstract void displayDetails();
}
class Student extends Person {
int rollNumber;
public Student(String name, int age, int rollNumber) {
super(name, age);
this.rollNumber = rollNumber;
}
void displayDetails() {
System.out.println("Student Details:");
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Roll Number: " + rollNumber);
}
}
class Teacher extends Person {
String subject;
public Teacher(String name, int age, String subject) {
super(name, age);
this.subject = subject;
}
void displayDetails() {
System.out.println("Teacher Details:");
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Subject: " + subject);
}
}
public class Assignment2p3 {
public static void main(String[] args) {
Student student = new Student("Alice", 20, 101);
Teacher teacher = new Teacher("Mr. Smith", 40, "Mathematics");
student.displayDetails();
teacher.displayDetails();
}
}