Advanced Class Design Flashcards

1
Q

Which keyword must be used in a class declaration if any of its methods uses the abstract keyword?

A

abstract

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

How do the contents of an abstract class differ from those of an interface?

A

An abstract class can contain implementation, while an interface cannot.

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

Which name must an anonymous class reference to implement an interface or extend a class?

A

The name of the interface or class that the anonymous class implements or extends.

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

Which method does the Enum class provide to retrieve an ordinal value for an enumeration constant?

A

ordinal

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

Which restriction limits objects when using an abstract class?

A

An abstract class cannot be instantiated.

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

Which restriction limits implementation when using a final class?

A

A final class cannot be extended.

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

Which keyword is used to implement members of an interface?

A

implements

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

Which method does the Enum class provide to iterate through enumeration constants?

A

values

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

How do the contents of an abstract class differ from a concrete class?

A

An abstract class can contain abstract members, while a concrete class cannot.

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

Which three modifiers are implicit for fields declared in an interface?

A

public static final

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

Which keyword is used to implement abstract members of an abstract class?

A

extends

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

Which keyword is used to inherit members from one interface to another interface?

A

extends

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

Can a static field override a non-static field in a superclass?

A
Yes.
If the class declares a field with a certain name, then the declaration of that field is said to hide any and all accessible declarations of fields with the same name in superclasses, and superinterfaces of the class.

A hidden field can be accessed by using a qualified name if it is static, or by using a field access expression that contains the keyword super or a cast to a superclass type.

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

Can a static method override a non-static method in a superclass?

A

No! Java only allows:

  1. Overriding an instance method by an instance method and
  2. Hiding a static method by a static method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
Can the abstract modifier be placed before the access modifier public as in:
abstract public class TestClass { }
A

yes

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

Do Enum objects implement Comparable?

A

Yes.

17
Q

Can an abstract method be defined with access modifier private?

A

No

18
Q

Can an abstract method be defined with access modifier protected?

A

Yes

19
Q

What are the valid access modifier that can be used with an abstract method?

A

public protected

20
Q

What are the valid modifiers that can be used to define an abstract class?

A

Same as for a top level class: public abstract .

21
Q

What is the result of GPA.MID where GPA is an Enum class?

A

“MID” which is the value printed for the Name() method.

22
Q

Can abstract be used with a local innner class?

A

Yes.