Java Class Design Flashcards

1
Q

What does the phrase covariant return types describe?

A

An overriding method can return a subtype of the return type of the overridden method.

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

Which type determines the version of overridden method to execute using polymoprhism?

A

Object type

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

When overloading methods, what is the order of priority for matching argument data types?

A
  1. Explicit type
  2. Widening primitive conversion
  3. Widening reference conversion
  4. Boxing conversion
  5. Unboxing conversion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When overloading methods, if all overloaded methods fail to match, which parameters are considered next?

A

vargs

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

Which the method of the Object class is invoked when placing objects in a Hashtable?

A

hashCode

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

Which two things can be referenced from a standard import statement?

A

Packages and types

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

What is the visibility of a local variable?

A

Only within the code block that contains its declaration

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

Which three access modifiers are allowed for inner classes?

A

public, private, protected

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

Which access modifier is allowed when overriding a method with the access modifier public?

A

public

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

Which primitive-to-reference conversion is not supported when using covariant return types?

A

Autoboxing

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

Which keyword is used in a subclass constructor to explicitly invoke a superclass constructor?

A

super

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

Which exception is thrown if a specified type is not a subtype of the object type in a casting operation?

A

ClassCastException

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

Which method of the Object class compares references rather than their underlying field values?

A

equals

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

Which the method of the Object class is invoked for the toString method?

A

hashCode

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

Where is a package statement required to be in a source code file?

A

The first executable line

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

Which access modifier prevents a method from being overridden in a subclass?

A

final

17
Q

What is the only access modifier allowed for a top-level class?

A

public

18
Q

What is the visibility of an anonymous class?

A

Only within its own class declaration

19
Q

Which access modifiers are allowed when overriding a method with the access modifier protected?

A

Same or less restricting.

protected, public

20
Q

Which types can access a field or method declared with the access modifier protected?

A

Subclasses or classes in same package

21
Q

When overloading methods, if there is not an overloaded match after boxing conversion, then which conversion occurs next?

A

Unboxing conversion

Widening is the answer from Kaplan

22
Q

Which operator tests whether a type is an instance of a specified class using the inheritance hierarchy?

A

instanceof

23
Q

Which three access modifiers are allowed for class and instance members?

A

public, private, protected

24
Q

Which type determines the version of a hidden member to use without polymoprhism?

A

Reference Type

25
Q

When overloading methods, if there is not an overloaded match after unboxing conversion, then which conversion occurs next?

A

No clear..

Widening is the answer from Kaplan

26
Q

Which the method of the Object class determines the bucket in which an object is placed in a Hashtable?

A

hashCode

27
Q

Which superclass constructor is implicitly invoked by the compiler in a subclass that does not explicitly invoke a specific superclass constructor?

A

Constructor with no arguments.

28
Q

What are the three class modifiers that can be used with an outer class?

A

public, abstract, final

29
Q

Can a constructor have both super and this in the body?

A

No, calls to super() or this() should be the first statement in a constructor, hence both the calls cannot be there in a constructor.