Chapter 16: Inheritance Flashcards
How do we delete an element from a partially filled array?
Replace unwanted item with end item. Decrease length by 1
What is UML?
Unified modelling language. Set of diagrams showing relationships between entities
What is a UML Class diagram?
Represents an inheritance hierarchy. Each class appears as a box with: Name, variables, methods, - means private, + means public, Italics means abstract
What is inheritance
A class might inherit properties from another. A class classifies objects, sometime we want sub-classes that have something in common
How does a subclass constructor start?
With a call to super class constructor. This can be an explicit or implicit invoke.
Describe objects as the route of the inheritance hierarchy
All objects are instances of the object class. Unless it explicitly extends another class, it extends object directly. All classes reside in a single inheritance hierarchy with object at the route. Every class except object has a superclass.
Describe how a method can be overridden
Sometimes a subclass needs to change the definition of an instance method. It redefines it and overrides the inherited definition
What is polymorphism?
A thing can have more than one form: a thing can have more than one type. A bike is a vehicle and is an object
What is dynamic method binding?
The process of determining at run time which actual method to invoke. When the compiler is producing the byte code for an instance method it doesn’t know which will get called. i.e. two sub-classes that both override the same method from the same superclass.
Some call can invoke different versions of method at different times depending on the run time value of object refrence
What is an abstract class?
No instances can be made. We dont want any direct instances of a class. It can only be implemented through its sub-classes.
What is an abstract method?
An instance method that has non-static modifiers, return type, name, method parameters, no method body.
We are saying “This method exists but we dont implement it here”. Implemented by subclass shown using ; Every subclass must implement it (rather than override)
What is a final method or class?
No subclass may override a public instance method if we declare it to be final. A class that cannot have any sub-classes
How can a subclass extend a superclass?
Add object state- adding instance variables
Add instance methods
How do we test for an instance of a class?
x Instance of y
How do we cast to a subclass?
An instance of a subclass is an instance of its superclass too Vehicle v = new Bicycle() Bicycle b = (Bicycle) v The compiler accepts this, any errors through a class cast exception at run time. This doesn't create a new object it just checks the format