Chapter 5 - Class Design Flashcards Preview

JAVA 8 OCA > Chapter 5 - Class Design > Flashcards

Flashcards in Chapter 5 - Class Design Deck (54)
Loading flashcards...
1

What are the rules for a concrete class to extend an abstract class?

1. The concrete class should implement all the methods from the abstract class.

Abstract classes extending abstract classes do not need to implemet the methods from the class that is being extended.

2

Can an abstract class be instantiated directly?

False

3

Do abstract classes require abstract and no abstract methods to be defined?

No. Abstract classes may define any number or zero abstract or non-abstract methods.

4

Can abstract classes may be marked as private, protected or final?

No. By any means abstract classes can be marked as private, protected or final.

5

Does an abstract class that extends an abstract class inherits all of its abstract methods as is own abstract methods?

True

6

Does the first concrete class that extends an abstract class must provide an implementation for all the inherited abstract methods?

True

7

Must abstract methods only be defined in abstract classes?

Yes. Abstract methods cannot be defined in classes that are not abstract.

8

Can abstract methods be declared private or final?

No. Abstract methods cannot be of the type private or final.

9

What are the rules for implementing an abstract method?

1. The name and signature of the implemented method should be the same.

2. The visibility of the method in the subclass must be at least as accessible as the method in the parent class.

10

What an interface is?

An interface is a specialized kind of abstract class. It shares many of the same properties and rules as an abstract class.

11

Can an interface be intanciated directly?

No. This is the interfaces rule # 1. Interfaces as abstract classes cannot be directly instantiated.

12

Must interfaces define methods?

No. An interface is not required to define methods.

13

Can an interface be defined as final?

No. This is interfaces rule #3. An interface may not be marked as final.

14

Must interfaces have the abstract keyword in them?

No. Top level interfaces are asume to be abstract whether the "abstract" keyword id present or not.

15

What will happen if an interface method is marked as private, protected or final?

A compiler error will be emitted. All top level interfaces are assume to be abstract whether the keyword is present or not. Therefore it is not possible to make a method private, protected or final.

16

Can a nondefault method in an interface be marked as private, protected or final?

No. This will trigger a compiler error. All nondefault methods in an interface are assume to have the modifiers abstract and public in their definition. So, defining methods as private, protected or final should not be done.

17

What is the inheriting an interface rule # 1?

An interface that extends another interface, as well as an abstract class that implements an interface, inherits all the abstract methods as its own abstract methods.

18

What is the inheriting an interface rule # 2?

The first concrete class that implements an interface, or extends an abstract class that implements an interface, must provide an implementation for all the inherited abstract methods.

19

Can an abstract class extend several abstract classes at the same time?

No. Just one abstract class can be extended at a time.

20

Can multiple interfaces be extended at the same time?

Yes. An interface may extend multiple interfaces.

Example:

public interface Seal extends HasTail, HasWhiskers{ }

Where HasTail and HasWiskers are interfaces.

21

Do abstract classes must include ‘abstract’ keyword in their definition?

Yes, abstract classes must include abstract keyword.

22

Do interfaces must include ‘abstract’ keyword in their definition?

No, they may or not include ‘abstract’ in their definition. If not included, Java includes it by default.

23

Can a class extend an interface?

No. A class can only implement an interface.

24

Can an interface implement another interface?

No. An interface can only extend another interface.

25

Can a interface extend a class?

No. An interface cannot extend a class. This generates a compiler error.

26

Can 2 methods in a class be defined with the same name and input parameters but different return type?

No. The code won’t compile.

27

What is rule # 1 for Interface Variables?

Interface variables are assumed to be public, static and final.

28

Can interface variables be private or protected?

No. This will trigger a compiler error.

29

What is rule # 2 for Interface Variables?

The value of an interface variable must be set when it is declared since it is marked as final.

Interface variables are essentially constant variables defined on the instance level. Because they are assumed to be static, they are accessible even without an instance of the interface.

30

Can default interface methods be declared within a class or abstract class?

No. A default method may only be declared within an interface.