2. Advanced class design Flashcards

1
Q

What is the natural sorting order of enums?

A

The natural order of enums is the order in which they are defined

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

Are anonymous classes final?

A

Anonymous classes are implicitly final

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

Can an anonymous class be static?

A

Anonymous classes can NEVER be static!

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

How can a static method of an interface be accessed?

A

An static method of an interface can only be accessed by using the name of that interface

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

Wich acces modifier does a enum constructor have?

A

Enum constructors are always private. If an enum type has no constructor declaration, then a private non-arg constructor is automatically provided

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

Is an enum final?

A

An enum is implicitly final

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

With two methods does the compiler provides an enum?

A

public static values() and public static valueOf(String)

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

What does values() return?

A

values() returns an array of it constants

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

what does Enum.valueOf(String) return?

A

valueOf(String) tries to match the string argument exactly with an enum constant. returns constant if successful else illegalArgumentException

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

can an enum be defined inside any class?

A

A public (or non-public) enum can be defined inside any class

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

Can an enum be defined as static?

A

An enum can be defined as a static member of any class. You can also have multiple public static enums inside the same class

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

Can an enum be defined inside a method or constructor?

A

An enum cannot be defined inside any method or constructor

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

What does the enum method ordinal() do?

A

Enums have a method ordinal(), with returns the index starting with 0

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

What does the enum method name() do?

A

Enums have a method name(), with returns the name of this enum constants

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

Can you acces a non-final static field from an enums constructor?

A

You cannot access a non-final static field from an enums constructor

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

What can an interface implement?

A

An interface cannot implement anything!

17
Q

Can en Enum extend any other enum or class?

A

An enum cannot extend any other enum or class, but is allowed to implement interfaces

18
Q

Can you override the enums clone method?

A

You cannot override the clone method because it is final.

19
Q

What can you acces when the interclass is non static?

A

All the static and non static members of the outerclass