Abstract Classes Flashcards

1
Q

1) Abstract classes

You can declare a class as abstract.
Once a class has been declared in this way it means that you are not allowed to c______ o_______ of that class.

A

create objects

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

2) Why would you want to declare a class as ‘abstract’?

A

Some classes work well as a template or a base class, whose attributes and methods can be inherited by subclasses.
It is the subclasses that we would use to create objects that are better suited to real-world objects.
See Java in two Semesters, chp 9, p. 251

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

3) How to declare a class as abstract?

Place the keyword abstract in the h__________:

e.g.

public abstract class Employee

A

header

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

4) The ‘final’ Modifier

The keyword final can be used to modify a variable and turn it into a constant.
It can also be used to modify a c_____ and a m______.

In the case of a class it is placed before the class declaration, like this:

public final class SomeClass
{
// code goes here
}

A

class
method

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

5) What does the ‘final’ keyword do if we use it to modify a class?

e.g.

public final class SomeClass
{
// code goes here
}

A: It means that the class cannot be s_____________.

A

subclassed

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

6) What does the ‘final’ keyword do if it is used to modify a method?

e.g.

public final void someMethod()
{
// code goes here
}

A: It means that the method cannot be o___________.

A

overridden

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

7) The toString Method

The toString method allows us to display all the i__________ about an object without having to invoke a lot of individual m___________ each time. (Great for testing!)

toString belongs to the Object class and is therefore inherited by all classes, and can be overridden for each individual class.

e.g.

@Override
public String toString() \here the String method is being overloaded
{
return “Name: “ + accountName + ‘\n’ + “Account number: “ + accountNumber + ‘\n’
+ “Balance: “ + balance;
}

A

information
methods

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

8)

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