Inheritance Flashcards

1
Q

1) Definition - Inheritance

Object-oriented programming languages provide the ability to e_______ existing classes by adding attributes and
methods to them. Not directly, though!

We create a subclass that inherits all of the features of the base-class, we can then add whatever we like to the sub-class.

This is called inheritance.

A

extend

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

2) How to link a sub-class to a base-class?

We use the keyword _____________ in the header of the sub-class to link them.

e.g.
public class PartTimeEmployee extends Employee // this class is a subclass of Employee

A

extends

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

3) .toString

A toString() is an in-built method in Java that returns the value given to it in string format. Hence, any object that this method is applied on, will then be returned as a string object.

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

4) Java Annotation.

Annotations begin with the @ symbol, and always start with an u_____ case letter.

e.g. @Override

Although it is not mandatory that we include this annotation, it is very good practice to do so. Its purpose is to inform the compiler that we are overriding a method from the superclass.

A

upper

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

5) Important Note

You can call a super class m_______ from within a sub class method.

BUT you CAN’T call a sub class method from within a super class method.

The conversion of a superclass type into subclass type is called SPECIALIZATION in java.

Specialization means going down from a more general form to a more s______ form. Thus, its s______ will be narrowed. Hence, this conversion is also called narrowing or down-casting in referenced data types.

A

method
specific
scope

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

6) Method Overriding

In the case of method overriding in subclasses, the methods have the same parameter list but belong to different c_______
—the superclass and the subclass.
In this case, they are distinguished by the o__________ with which they are associated.

Basically, using the same methods for different objects!

See chp. 9, pp 249-250

A

classes
object

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

7) The ‘final’ modifier

The ‘final’ modifier can also be used to modify a class.
This means that the class cannot be s__________.

The ‘final’ modifier can also modify a method.
This means that the method cannot be o___________.

A

subclassed
overridden

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

8) Inheriting from Object Class

Every new class that you define automatically inherits from the Object class.
The Object class defines ___ methods, therefore each subclass of Object inherits these methods.
These 11 methods can be called on objects of any class.

A

11

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

9) Abstract Classes

An abstract class is simply a class that you CANNOT create objects from, or in more technical terms, i___________
object from.
For example, a base class that is far too general. It would be better to make objects from sub classes that are more detailed.

A

instantiate

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

10)

To make a class an ‘abstract’ class simply put the word ‘abstract in the class h___________

e.g. public abstract class Cat {

}

A

header

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

11) Abstract Methods

In any absract classes, you can make abstract methods.
When you make a method abstract, you don’t specify a b_____ for the method. You just declare it and end it with a
s_______________

e.g.

public abstract class Animal {
int age;
String name;

public abstract void makeNoise( ) ;

}

A

body
semi-colon

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

12) Why would you make a method abstract, in an abstract class?

Just like the super class is very general, a method in that class could also be too general. E.g. An animal class with a method called ‘makeNoise’. It would be something non-specific like, “Hello, I am an animal”.
This might not be useful in sub classes where we could specifiy the noise an individual animal might make.

Why not just remove the method from the super class?

A

Because we want that method to be a part of every sub class. We want our animals to make a noise and this forces each and every subclass to include the method.

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

13) Wrapper Classes

For every p_____________ data type we have wrapper classes’

A

primitive

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

14)

The name of the wrapper class is similar to the basic type, but begins with a c_______ letter
—for example Integer,Character, Float, Double.

They are called wrappers because they “wrap” aclass around the basic type.

A

capital

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

15) What are wrapper classes?

A wrapper class provides a way to use primitive date types as reference types.
a String is an example of a r__________ data type.

Refrence data types cointain useful m________.
Reference data types can be used in certain collections, e.g. ArrayList

A

reference
methods

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

16) Why use wrapper classes?

One use is for ArrayList. ArrayList cannot hold p___________ data types, so we use wrapper classes to make them useable.

A

primitive