Java Class Design Flashcards
What does the phrase covariant return types describe?
An overriding method can return a subtype of the return type of the overridden method.
Which type determines the version of overridden method to execute using polymoprhism?
Object type
When overloading methods, what is the order of priority for matching argument data types?
- Explicit type
- Widening primitive conversion
- Widening reference conversion
- Boxing conversion
- Unboxing conversion
When overloading methods, if all overloaded methods fail to match, which parameters are considered next?
vargs
Which the method of the Object class is invoked when placing objects in a Hashtable?
hashCode
Which two things can be referenced from a standard import statement?
Packages and types
What is the visibility of a local variable?
Only within the code block that contains its declaration
Which three access modifiers are allowed for inner classes?
public, private, protected
Which access modifier is allowed when overriding a method with the access modifier public?
public
Which primitive-to-reference conversion is not supported when using covariant return types?
Autoboxing
Which keyword is used in a subclass constructor to explicitly invoke a superclass constructor?
super
Which exception is thrown if a specified type is not a subtype of the object type in a casting operation?
ClassCastException
Which method of the Object class compares references rather than their underlying field values?
equals
Which the method of the Object class is invoked for the toString method?
hashCode
Where is a package statement required to be in a source code file?
The first executable line
Which access modifier prevents a method from being overridden in a subclass?
final
What is the only access modifier allowed for a top-level class?
public
What is the visibility of an anonymous class?
Only within its own class declaration
Which access modifiers are allowed when overriding a method with the access modifier protected?
Same or less restricting.
protected, public
Which types can access a field or method declared with the access modifier protected?
Subclasses or classes in same package
When overloading methods, if there is not an overloaded match after boxing conversion, then which conversion occurs next?
Unboxing conversion
Widening is the answer from Kaplan
Which operator tests whether a type is an instance of a specified class using the inheritance hierarchy?
instanceof
Which three access modifiers are allowed for class and instance members?
public, private, protected
Which type determines the version of a hidden member to use without polymoprhism?
Reference Type
When overloading methods, if there is not an overloaded match after unboxing conversion, then which conversion occurs next?
No clear..
Widening is the answer from Kaplan
Which the method of the Object class determines the bucket in which an object is placed in a Hashtable?
hashCode
Which superclass constructor is implicitly invoked by the compiler in a subclass that does not explicitly invoke a specific superclass constructor?
Constructor with no arguments.
What are the three class modifiers that can be used with an outer class?
public, abstract, final
Can a constructor have both super and this in the body?
No, calls to super() or this() should be the first statement in a constructor, hence both the calls cannot be there in a constructor.