Powered by Blogger.

Java - Definition of Invoking Parent Class Constructor in Java

Definition of Invoking Parent Class Constructor:-

A sub-class constructor can invoke a super-class constructor using the super keyword. In line 19, show the parent class constructor invoking.

 Invoking Parent Class Constructor Program:-

 class Employee1{
   public String name;
   public float salary;

   public Employee1(String name,float salary){
      this.name = name;
      this.salary = salary;
   }

   public void showDetails(){
      System.out.println(”Name: ”+name+” Salary: ”+salary);
   }
 }

 public class Manager1 extends Employee1{
   public String department;

   public Manager1(String department){
      super(”Mahmud”,50000F);
      this.department = department;
   }

   public void showDetails(){
      super.showDetails();
      System.out.println(”Department:”+department);
   }

   public static void main(String[]args){
      Manager1 m = new Manager1(”Engineering”);
      m.showDetails();
   }
 }

0 comments:

Post a Comment