Inheritance

Capability of a class to retrieve properties and characteristics from another class

  • first you create a superclass which is then extended by subclasses
public class cars {
    int a;
}
public class sub extends cars {
    
}

Writing constructors

  • allows reuse of code and able to add attributes
  • a subclass can be further extended and turn into a super class
  • constructor can be used to call super class constructor and add attributes

Overriding

  • <mark>@Override</mark> gives different implementations to method of superclass
public String toString() {
    return + " was born " + birthdayl
}

@Override
public String toString() {
    return super.getName() + " is in grade" + grade;
}

Making References

  • organized into single root tree called inheritance hierarchy
  • attributes and methods are inherited to lower levels
  • object and reference type can be different

Polymorphism

  • used when there are multiple classes related to inheritance
  • used when method is implemented to perform different tasks in different classes
  • allows method to take multiple forms
  • useful for code resuability