Lecture 9 Flashcards
What is inheritance?
Inheritance allows us to create classes that are subclasses of other classes.
What are three different ways of describing: “A inherits B”
A is a subclass of B, A is derived from B, A is the child of B.
What are two different ways of describing: “B is inherited by A”
B is a superclass of A, B is the parent of A.
What two things are true about an object of class A, if class A inherits class B?
Every object, that is an instance of the subclass has all the properties from the superclass On such an object, you can call all methods of the superclass.
What is the: “Liskov substitution principle”?
If A is a superclass of B, then everywhere in the program where an object of Class A is requested, an object of class B is also accepted.
How do you define in Java that A is a subclass of B?
In the signature of A add “extends B”
What can access something that is ‘public’?
everything
What can access something that is ‘private’?
Only things inside the class
What can access something that has no access type specified?
The class and the package
What can access something that is ‘protected’?
The class, the package, and subclasses.
How can you call the constructor of a parent?
super()
What is the concept of Polymorphism
Everywhere where a class X is allowed, a subclass Y of x is also allowed, but NOT the other way around.
When can you get a ‘ClassCastException’?
When you try to cast something to a class, which it can’t be cast to.
What is method overriding?
Creating a method with the same signature as an already existing method in the inheritance-architecture but in a different class of the inheritance-architecture.
What is method overloading?
Creating a method with the same name as another method inside the class (or inheritance-architecture), but with a different parameter list (different amount, types or order).