1) Which of the following is true regarding subclasses Select one: a. A subclass
ID: 3677255 • Letter: 1
Question
1) Which of the following is true regarding subclasses
Select one:
a. A subclass object may be converted to a superclass object.
b. A subclass object cannot be converted to a superclass object.
c. A superclass object cannot be converted to a subclass object.
d. Superclass and subclass objects automatically convert to each other when needed.
2) Consider the following code snippet:
Object obj;
BankAccount ba;
SavingsAccount sa;
String str;
Which of the following assignments is not legal?
Select one:
a. ba = sa;
b. sa = str;
c. obj = str;
d. obj = sa;
3) All object references ____.
Select one or more:
a. Can be converted to the type Object without requiring a cast.
b. Can be converted to a subclass type without requiring a cast.
c. Can be converted to a superclass type without requiring a cast.
d. Require a cast to convert them.
4) A class that represents a more specific entity in an inheritance hierarchy is called a/an ____.
Select one:
a. Default class
b. Superclass
c. Subclass.
d. Inheritance class.
Explanation / Answer
1) The correct option is c.A superclass object cannot be converted to a subclass object.
Explantion: If sub class inherits superclass, then the subclass references the super class.
But the superclass object cannot be converted to a subclass object automaically.
A casting from upcasting to down casting is required. If casting is not proper
then runtime error is occured.
------------------------------------------------------------------------------------------------------
2)The correct option is b. sa = str;
Explanation: The str is a string variable.
sa is an object of SavingsAccount class.
So str object cannot be assigned to the SavingsAccount class object
Compatability mismatch occurs.
------------------------------------------------------------------------------------------------------
3)The correct option is a. Can be converted to the type Object without requiring a cast.
Explanation : Object class is the root class in the java lang package.
All object references can be converted to the Object type
------------------------------------------------------------------------------------------------------
4)The correct option is c. Subclass.
Explanation : The more specific class is called subclass
or concrete class. An object can be created to the subclass more specific attributes
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.