Java Project - School Management System

Java Project - School Management System

A School Management System using Java Inheritance.

?? Features:

? Single Inheritance: Person → Student, Teacher

? Method Overriding: Different implementations of displayInfo()

? Encapsulation: Private attributes with getters and setters


?? Java Code: School Management System


// Parent Class: Person

class Person {

protected String name;

protected int age;

// Constructor

public Person(String name, int age) {

this.name = name;

this.age = age;

}

// Method to display person info (Overridden in child classes)

public void displayInfo() {

System.out.println("Name: " + name);

System.out.println("Age: " + age);

}

}

// Child Class: Student (inherits from Person)

class Student extends Person {

private int studentId;

private String grade;

// Constructor

public Student(String name, int age, int studentId, String grade) {

super(name, age);

this.studentId = studentId;

this.grade = grade;

}

// Overriding displayInfo() to include student-specific details

@Override

public void displayInfo() {

super.displayInfo();

System.out.println("Student ID: " + studentId);

System.out.println("Grade: " + grade);

}

}

// Child Class: Teacher (inherits from Person)

class Teacher extends Person {

private String subject;

private double salary;

// Constructor

public Teacher(String name, int age, String subject, double salary) {

super(name, age);

this.subject = subject;

this.salary = salary;

}

// Overriding displayInfo() to include teacher-specific details

@Override

public void displayInfo() {

super.displayInfo();

System.out.println("Subject: " + subject);

System.out.println("Salary: $" + salary);

}

}

// Main Class

public class SchoolManagementSystem {

public static void main(String[] args) {

// Creating a Student object

System.out.println("\n--- Student Information ---");

Student student1 = new Student("Alice Johnson", 16, 101, "10th Grade");

student1.displayInfo();

// Creating a Teacher object

System.out.println("\n--- Teacher Information ---");

Teacher teacher1 = new Teacher("Mr. Smith", 40, "Mathematics", 50000);

teacher1.displayInfo();

}

}


?? Explanation:

1. Parent Class: Person

  • Attributes: name, age
  • Method: displayInfo()
  • Base class for both Student and Teacher

2. Child Class: Student (Inherits Person)

  • Additional Attributes: studentId, grade
  • Overrides displayInfo() to include student details

3. Child Class: Teacher (Inherits Person)

  • Additional Attributes: subject, salary
  • Overrides displayInfo() to include teacher details

4. Main Class: SchoolManagementSystem

  • Creates Student and Teacher objects
  • Calls displayInfo() to show information


?? Key OOP Concepts Demonstrated

? Inheritance: Student and Teacher inherit from Person

? Method Overriding: displayInfo() behaves differently in child classes

? Encapsulation: Private attributes with constructors to initialize values

要查看或添加评论,请登录

Sridhar Raj P的更多文章

  • JavaScript Learning Path ??

    JavaScript Learning Path ??

    JavaScript Learning Path ?? This structured path will take you from JavaScript basics to advanced concepts, helping you…

  • CSS Learning Path ??

    CSS Learning Path ??

    CSS Learning Path ?? This structured path will take you from CSS basics to advanced styling techniques, helping you…

  • HTML Learning Path ??

    HTML Learning Path ??

    HTML Learning Path ?? This structured path will guide you from HTML basics to advanced concepts, helping you build web…

  • Full Stack React JS + Spring Boot Learning Path

    Full Stack React JS + Spring Boot Learning Path

    Full Stack React JS + Spring Boot Learning Path ?? This structured path will help you master React JS for the frontend…

    4 条评论
  • Core Python Learning Path

    Core Python Learning Path

    Core Python Learning Path ?? This path focuses on mastering Python fundamentals, essential for any Python-based career.…

    2 条评论
  • Python Learning Paths

    Python Learning Paths

    Python has multiple learning paths depending on your goals. Here are some structured learning paths for different…

    3 条评论
  • Custom Hook

    Custom Hook

    Custom Hooks are a powerful feature introduced in React 16.8 that allow developers to extract and reuse stateful logic…

  • useReducer() Hook in React JS – Example & Explanation

    useReducer() Hook in React JS – Example & Explanation

    Hook in React JS – Example & Explanation The hook is an alternative to for managing complex state logic in React…

  • useReducer() Hook in React JS – Example & Explanation

    useReducer() Hook in React JS – Example & Explanation

    Hook in React JS – Example & Explanation The hook is an alternative to for managing complex state logic in React…

  • Passing Data from Child to Parent Component in React JS using Hooks

    Passing Data from Child to Parent Component in React JS using Hooks

    Passing Data from Child to Parent Component in React JS using Hooks In React, data flows from parent to child via…

社区洞察

其他会员也浏览了