Inheritance in Object-Oriented Programming
What is commonly used in object-oriented programming to ensure derived class methods behave correctly?
Polymorphism testing with superclass references.
Recursion analysis for base and derived classes.
Algorithmic time complexity comparison.
Loop unrolling within inheritance structures.
Assuming multiple inheritance is allowed and classes FlyingObject
and Watercraft
both have a default void method named 'activate', which implementation will be inherited in class 'Seaplane' without explicit override, given that 'Seaplane' extends both?
The activate() from FlyingObject is inherited due to lexical order.
This situation results in a compilation error due to ambiguity between parent class methods.
The activate() from Watercraft takes precedence as it's considered more specialized.
Both methods are inherited but neither can be used unless disambiguated by Seaplane.
Given an unsorted array, which algorithm would not be recommended if you need to prioritize memory efficiency and the input size is large?
QuickSort with recursion
In-place QuickSort with iteration
Iterative Merge Sort
Heap Sort without recursion
Which principle is best demonstrated when an array of type Animal
contains elements like Dog
, Cat
, and Bird
that all extend from Animal
?
Interface implementation
Class abstraction
Code encapsulation
Subtype polymorphism
After successfully instantiating an object with 'new', what must always be followed by this expression?
A semicolon indicating end-of-the statement unless used in creational expressions like array initialization.
A cast operator matching either an interface or abstract class implemented/extended by the instantiated class.
A reference type that matches or is a supertype of the instantiated class' type.
An integer specifying how many objects should be created.
Given a base class Animal
and derived classes Mammal
, Bird
, and Fish
, which instantiation correctly demonstrates polymorphism?
Bird myPet = null
Animal myPet = new Fish()
Mammal myPet = new Bird()
Fish myPet = new Animal()
If Class C is a superclass of Class B and a subclass of Class A, which of the following is NOT valid?
C c = new C();
C b = new B();
A c = new C();
B c = new C();

How are we doing?
Give us your feedback and let us know how we can improve
When designing software that includes classes representing different kinds of bank accounts like SavingsAccount and CheckingAccount derived from Account, why might you make Account an abstract class rather than concrete?
To force developers to create additional classes for different account types, promoting code reusability.
Because concrete classes are less efficient than abstract classes in terms of memory management.
So that instances of Account cannot be created, preventing undesired usage of generic account features.
To ensure account-specific functionality must be defined in each subtype since some behaviors cannot be generalized for all accounts.
If Class J is a superclass of Class K and Class L, which of the following are valid?
“J j = new J();” and “J k = new K();”
“J j = new J();”, “J k = new K();”, and “J l = new L();”
“J j = new J();” and “J l = new L();”
“J k = new K();”, and “J l = new L();”
If class I extends class H, and class P extends class I, what is the direct superclass of class P?
I
H
P does not have a direct superclass
P