Chapter 5: Class Design Flashcards

1
Q

How can Java support multiple inheritance?

A

Through the use of interfaces

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

Does Java support multiple levels of inheritance?

A

Yes

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

How can you prevent a class from being extended?

A

By using the ‘final’ keyword

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

When extending a class without a no-argument constructor, what do you need to do?

A

Explicitly call super() with valid arguments for one of the super class’s constructors

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

T or F. You can execute code in the constructor before calling super()

A

False

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

Which is executed first? Parent or child constructor?

A

Parent

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

How can you access parent members?

A

Both ‘this’ and ‘super’ will work for inherited members

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

What are the requirements for overriding?

A

Must have the same signature
Child must be at least as accessible as the parent
Child may not throw a checked exception that is new or broader than one thrown by parent method
Return type must be same or subtype of parent return type

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

T or F. A subclass can have a method with the same name as a private method in the parent class

A

True

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

How can you explicitly call the parent’s version of an overridden method?

A

Using the ‘super’ keyword

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

What is a hidden static method?

A

A static method that has been overridden. Both must be static

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

Which version of a method is called if an overridden method is called on a child object in the parent class?

A

The child version

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

Which version of a method is called if a hidden method is called on a child object in the parent class?

A

The parent version

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

How do you prevent a static method from being hidden?

A

Make it ‘final’

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

What are the rules for defining an abstract method?

A

No implementation is provided in the class where it’s declared
It cannot be final
It can only be defined in an abstract class or interface
It cannot be private

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

What is a concrete class?

A

The first non-abstract class to extend an abstract class

17
Q

What must a concrete class do?

A

Must implement all inherited abstract methods

18
Q

What keyword is used when an interface inherits from another interface?

A

extends

19
Q

What keyword is used when an abstract class inherits from an interface?

A

implements

20
Q

What are variables assumed to be in an interface?

A

public static final

21
Q

What are methods assumed to be in an interface?

A

public abstract

-Unless they are static

22
Q

Can an interface be instantiated directly?

A

No

23
Q

Can an interface extend a concrete class?

A

No

24
Q

T or F. Static methods in interfaces are inherited by classes that implement the interface?

A

False

25
Q

How do you call a static method in an interface?

A

By using the name of the interface class

26
Q

T or F. You can’t implement two interfaces with the same method name

A

False. You can implement one of those methods to satisfy both interfaces

-Unless return types are different

27
Q

What is unique about default methods in comparison to other abstract methods?

A

They aren’t required to be implemented

They have a method body

28
Q

If you cast a reference variable to the parent type, can you still access subclass members?

A

No. You can only access members available to the reference type

28
Q

If you cast a reference variable to the parent type, can you still access subclass members?

A

No. You can only access members available to the reference type

29
Q

When you cast an object to a different type, is it’s type changed in memory?

A

No

30
Q

T or F. You must explicitly cast a subclass to superclass

A

False

31
Q

T or F. You don’t need to explicitly cast a superclass to a subclass

A

False

32
Q

T or F. You may cast to unrelated types

A

False

33
Q

What is a virtual method?

A

A method whose implementation isn’t determined until runtime