Chapter 16: Inheritance Flashcards

1
Q

How do we delete an element from a partially filled array?

A

Replace unwanted item with end item. Decrease length by 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is UML?

A

Unified modelling language. Set of diagrams showing relationships between entities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a UML Class diagram?

A

Represents an inheritance hierarchy. Each class appears as a box with: Name, variables, methods, - means private, + means public, Italics means abstract

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is inheritance

A

A class might inherit properties from another. A class classifies objects, sometime we want sub-classes that have something in common

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does a subclass constructor start?

A

With a call to super class constructor. This can be an explicit or implicit invoke.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe objects as the route of the inheritance hierarchy

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe how a method can be overridden

A

Sometimes a subclass needs to change the definition of an instance method. It redefines it and overrides the inherited definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is polymorphism?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is dynamic method binding?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an abstract class?

A

No instances can be made. We dont want any direct instances of a class. It can only be implemented through its sub-classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an abstract method?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a final method or class?

A

No subclass may override a public instance method if we declare it to be final. A class that cannot have any sub-classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can a subclass extend a superclass?

A

Add object state- adding instance variables

Add instance methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do we test for an instance of a class?

A

x Instance of y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do we cast to a subclass?

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Descibe is a and has a

A
Every instance of subclass is a superclass
If class c has instance variable d c has a d
17
Q

How do we use an overridden method?

A

super.method()

18
Q

What is constructor chaining?

A

When a constructor method is invoked, the first thing is either to call another constructor in the same class of to call constructor method in superclass

19
Q

Describe overload and override

A
Overload: two methods have the same name in the same class bu a different signature
Override: methods in the subclass has the same signature as one in the superclass- it overrides it
20
Q

How can an accidental overload occur?

A

We may think we have overridden a method but instead we have overloaded it. Dynamic method binding chooses current method implementation at run time

21
Q

How do we show multiple constructors?

A

To explicitly show the relationship alternative constructors could call the original using this(10, true) ie filling in a default value for one of the parameters

22
Q

What happens if you do not write a constructor?

A

There is a default which calls super()

23
Q

Describe to string and print ln

A

Println is an overloaded method for every primitive type of method argument. There is also an instance for obejcts. When we write a toString method, we override this.