-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathest.java
More file actions
47 lines (38 loc) · 1.05 KB
/
est.java
File metadata and controls
47 lines (38 loc) · 1.05 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
abstract class Person {
String name;
int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
abstract void displayDetails();
}
class Student extends Person {
String course;
Student(String name, int age, String course) {
super(name, age);
this.course = course;
}
void displayDetails() {
System.out.println("Student: " + name + ", Age: " + age + ", Course: " + course);
}
}
class Teacher extends Person {
String subject;
Teacher(String name, int age, String subject) {
super(name, age);
this.subject = subject;
}
void displayDetails() {
System.out.println("Teacher: " + name + ", Age: " + age + ", Subject: " + subject);
}
}
public class est {
public static void main(String[] args) {
Person p;
p = new Student("Arya", 21, "Computer Science");
p.displayDetails();
p = new Teacher("Mr. Sharma", 45, "Java");
p.displayDetails();
}
}