Skip to content
Snippets Groups Projects
Commit faec20a5 authored by Syed Naqvi's avatar Syed Naqvi
Browse files

code skeleton - Ex-W6

parent db3a7bcc
No related branches found
No related tags found
No related merge requests found
package org.example;
// Abstract superclass
abstract class Person {
protected String name;
protected int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void greet() {
System.out.println("Hello, I am a member of the university.");
}
public abstract void displayDetails();
}
// Student subclass
class Student extends Person {
protected String studentID;
public Student(String name, int age, String studentID) {
super(name, age);
this.studentID = studentID;
}
@Override
public void displayDetails() {
System.out.println("Student Details: Name: " + name + ", Age: " + age + ", ID: " + studentID);
}
public void study() {
System.out.println("Student is studying.");
}
}
// Professor subclass
class Professor extends Person {
protected String specialization;
public Professor(String name, int age, String specialization) {
super(name, age);
this.specialization = specialization;
}
@Override
public void displayDetails() {
System.out.println("Professor Details: Name: " + name + ", Age: " + age + ", Specialization: " + specialization);
}
public void teach() {
System.out.println("Professor is teaching.");
}
}
// Staff subclass
class Staff extends Person {
protected String department;
public Staff(String name, int age, String department) {
super(name, age);
this.department = department;
}
@Override
public void displayDetails() {
System.out.println("Staff Details: Name: " + name + ", Age: " + age + ", Department: " + department);
}
public void work() {
System.out.println("Staff member is working.");
}
}
// Main class
public class ums {
public static void main(String[] args) {
Student student = new Student("Alice", 20, "S12345");
Professor professor = new Professor("Dr. Smith", 45, "Computer Science");
Staff staff = new Staff("Mr. Brown", 35, "Administration");
student.greet();
student.displayDetails();
student.study();
System.out.println();
professor.greet();
professor.displayDetails();
professor.teach();
System.out.println();
staff.greet();
staff.displayDetails();
staff.work();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment