Skip to content
Russell Saerang edited this page Sep 9, 2021 · 2 revisions

Inheritance

  • is-a relationship
  • The use of super(...) to access the parent's constructor
  • super.method() or super.attribute to access the parent's method and attribute accordingly
  • Example Code
class Parent {
    Parent(...) { ... }
    void foo(...) { ... }
    // some other methods
}

class Child extends Parent {
    Child(...) {
        super(...) // Must be the first statement of the constructor if needed
        // somethingelse()?
    }
}

private vs protected

Think of it as treating something like your private bedroom where only you can get in VS your family room where... your whole family can access!

Overriding (@Override) vs Overloading

  • Overriding: explicitly defining a method that is the same as the method inherited from another class
  • Overloading: having more than one methods to co-exists as long as the arguments are different in configuration
Clone this wiki locally