Lecture 2 Summary - nus-cs2030/2122-s1 GitHub Wiki
Inheritance
- is-a relationship
- The use of
super(...)
to access the parent's constructor super.method()
orsuper.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!
@Override
) vs Overloading
Overriding (- 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