Page 149 - CITS - CSA - TP (Volume 2) - Hindi
P. 149

कं  ूटर सॉ वेयर ए ीके शन - CITS




           टा  2: ए लॉयी और मैनेजर  ास:
                // Superclass
              class Employee {

                  String name;
                  double salary;



                  // Constructor
                  Employee(String name, double salary) {
                      this.name = name;

                      this.salary = salary;
                  }



                  void displayDetails() {
                      System.out.println(“Name: “ + name);

                      System.out.println(“Salary: $” + salary);
                  }
              }



              // Subclass
              class Manager extends Employee {

                  String department;



                  // Constructor
                  Manager(String name, double salary, String department) {
                      super(name, salary); // Call superclass constructor

                      this.department = department;
                  }


                  @Override
                  void displayDetails() {
                      super.displayDetails(); // Call superclass method
                      System.out.println(“Department: “ + department);
               }
           }


           // Main class

           public class EmployeeDemo {
               public static void main(String[] args) {



                                                           135

                                  CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 100
   144   145   146   147   148   149   150   151   152   153   154