This project demonstrates core Object-Oriented Programming (OOP) principles using Java, including:
- Inheritance: Building a class hierarchy of school staff.
- Encapsulation: Securing class attributes using access modifiers.
- Polymorphism: Achieved via upcasting and downcasting.
- Static Concepts: Usage of static variables, methods, and static blocks for shared resources.
-
Attributes (private):
String name
int age
String employeeId
-
Static Attribute:
String schoolName
– shared by all staff members
-
Methods:
String work()
– returns a string stating the staff is working.String details()
– returns staff details.
-
Static Methods:
void showSchoolName()
– prints the school name.
-
Static Block:
- Initializes the
schoolName
when the class is loaded.
- Initializes the
-
Additional Attribute:
String subject
-
Methods:
void setSubject(String subject)
– sets the teacher's subject.String teach()
– returns a message that the teacher is teaching the subject.String details()
– overrides parent method to include the subject info.
-
Additional Attribute:
int yearsOfExperience
-
Methods:
void setExperience(int experience)
– sets the principal's experience.String lead()
– returns a message indicating leadership.String details()
– overrides parent method to include experience.
Demonstrates the following concepts:
- 🔒 Encapsulation – access and modify attributes via getter/setter methods.
- 🔁 Upcasting – treat
Teacher
/Principal
objects asStaff
references to call shared methods. - 🔄 Downcasting – revert
Staff
reference to specific subclass to call unique methods. - 🧷 Static Variable/Method – shared
schoolName
is displayed using a static method. - ⚡ Static Block – initializes static data when class is loaded.
Feature | Description |
---|---|
Inheritance | Teacher and Principal extend Staff |
Encapsulation | Private attributes with public setters/getters |
Upcasting | Staff s = new Teacher() |
Downcasting | Teacher t = (Teacher) s |
Static Methods/Vars | Shared school name using static members |
Static Block | One-time initialization of static fields |
SchoolManagementSystem/
│
├── .classpath
├── .gitignore
├── .project
├── .settings/
│ ├── org.eclipse.core.resources.prefs
│ └── org.eclipse.jdt.core.prefs
│
├── src/
│ └── com/pentagon/smsp/
│ ├── Staff.java
│ ├── Teacher.java
│ ├── Principal.java
│ └── SMS.java <-- Main class
│
└── module-info.java
School Name is : Govt School
Priya teacher is teaching
name : Priya age 25 employeeId: emp01 subject: Maths
name : hari age 45 employeeId: emp05 years of experience:20 is leading the school with 20 of Experience
name : hari age 45 employeeId: emp05 years of experience:20
- Java (OOP Concepts)
- Eclipse IDE (or any preferred Java IDE)