Chapter 9 Quiz Flashcards

1
Q

Every class in Java, except ________, extends an existing.

A

Objects

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

Which superclass members are inherited by all subclasses of that superclass?

a. private instance variables and methods.
b. protected instance variables and methods.
c. private constructors.
d. protected constructors.

A

b. protected instance variables and methods.

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

Using the protected keyword gives a member:

private access
package access
block scope
public access

A

package access

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

Overriding a method differs from overloading a method because:

A

Overridden methods have the same signature

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

Superclass methods with this level of access cannot be called from subclasses

A

Private

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

The default implementation of method clone of Object performs a ________.

A

shallow copy

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

When a subclass constructor calls its superclass constructor, what happens if the superclass’s constructor does not assign a value to an instance variable?

A

The program compiles and runs because the instance variables are initialized to their default values

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

Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?

A

super

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

Inheritance is also known as the _______

a. knows-a relationship.
b. has-a relationship.
c. uses-a relationship.
d. is-a relationship.

A

d. Inheritance is known as the is-a relationship.

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

Which of the following is not a superclass/subclass relationship?

a. Employee/Hourly Employee.
b. Vehicle/Car.
c. Sailboat/Tugboat.
d. None of the above.

A

c. Sailboat/Tugboat (they are both different type of boats, they would both be subclasses of superclass boat.)

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

Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?

a. base.
b. this.
c. public.
d. super.

A

d. super (must be called in the default constructor of the subclass)

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

Superclass methods with this level of access cannot be called from subclasses.

a. private.
b. public.
c. protected.
d. package.

A

a. Private level access

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

private fields of a superclass can be accessed in a subclass

a. by calling private methods declared in the superclass.
b. by calling public or protected methods declared in the superclass.
c. directly.
d. All of the above.

A

b. By calling public or protected methods in the super class.

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

When overriding a superclass method and calling the superclass version from the subclass method, failure to prefix the superclass method name with the keyword super and a dot (.) in the superclass method call causes ________.

a. a compile-time error.
b. a syntax error.
c. infinite recursion.
d. a runtime error.

A

c. Infinite Recursion

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

A form of software reuse in which existing classes acquire the member of existing classes and embellish those classes with new capabilities.

A

Inheritance

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

What members of a super class can be accessed in the superclasses’s declarations and in the subclass declarations.

A

protected (public variables may be accessed as well but, this is a bad practice)

17
Q

In a _________________ relationship a subclass object can be treated as an object of its superclass.

A

Inheritance(is-a)

18
Q

In a ________________ relationship a class object has references to objects of other classes as members.

A

composition(has-a)

19
Q

in single inheritance a class exists in a(n)_________ relationship with its subclasses

A

is - a

20
Q

A superclasses’s _____________ members can be accessed anywhere the program has a reference to an object of that superclass or to an object of one of its subclasses

A

public

21
Q

When an object of a subclass is instantiated, a superclass _____________ is called implicitly or explicitly.

A

constructor

22
Q

Subclass constructors can call superclass constructors via the ________________ keyword.

A

Super