How can constructor chaining be done by using the super keyword?

DWQA QuestionsCategory: JavaHow can constructor chaining be done by using the super keyword?
satya asked 9 months ago

How can constructor chaining be done by using the super keyword?

1 Answers
Editor Staff answered 9 months ago

class Person
{
String name,address;
int age;
public Person(int age, String name, String address)
{
this.age = age;
this.name = name;
this.address = address;
}
}
class Employee extends Person
{
float salary;
public Employee(int age, String name, String address, float salary)
{
super(age,name,address);
this.salary = salary;
}
}
public class Test
{
public static void main (String args[])
{
Employee e = new Employee(22, “Mukesh”, “Delhi”, 90000);
System.out.println(“Name: “+e.name+” Salary: “+e.salary+” Age: “+e.age+” Address: “+e.address);
}
}
Output
Name: Mukesh Salary: 90000.0 Age: 22 Address: Delhi