Question 1
EasyMethod overloading is an example of:
- A.
Compile-time polymorphism
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
Method overloading is an example of:
Compile-time polymorphism
Run-time polymorphism
Encapsulation
Multiple inheritance
Answer: A
With overloading, the compiler chooses which method to call from the argument types, so it is resolved at compile time. Overriding is run-time polymorphism.
What does polymorphism mean in OOP?
Hiding data
Inheriting from many classes
One interface or name with many forms of behaviour
Creating many classes
Answer: C
The same method call can behave differently depending on the object or arguments.
Which kind of polymorphism is method overriding?
Compile-time polymorphism
Run-time (dynamic) polymorphism
Not polymorphism
Static binding
Answer: B
The method to run is chosen at run time from the actual object's class.
What is method overriding?
Defining two methods with the same name but different parameters in one class
Deleting a parent method
A subclass providing its own version of a method defined in the parent class
Calling a method twice
Answer: C
The overriding method has the same name and parameters as the parent method.
What is operator overloading?
Giving an operator a special meaning for user-defined types, e.g. + for complex numbers
Using operators in loops
Changing operator precedence
Using too many operators
Answer: A
C++ and Python support it; Java does not (except + for strings).
In C++, which keyword enables run-time polymorphism for a member function?
friend
inline
static
virtual
Answer: D
A virtual function is dispatched through the vtable based on the object's actual type.
What is the output of this code?
#include <iostream>
using namespace std;
class Shape {
public:
virtual void draw() { cout << "Shape"; }
};
class Circle : public Shape {
public:
void draw() override { cout << "Circle"; }
};
int main() {
Shape* s = new Circle();
s->draw();
delete s;
return 0;
}
Shape
Circle
Answer: B
draw() is virtual, so calling it through a Shape* that points to a Circle runs Circle::draw.
Which of these shows compile-time polymorphism?
Function overloading
Dynamic dispatch
Method overriding
Virtual functions
Answer: A
The compiler picks the overload from the argument types, so the choice is fixed at compile time.
What does the word 'polymorphism' literally mean?
Many forms
Hidden data
Many classes
One function
Answer: A
It comes from Greek: poly (many) + morph (form).
Run-time polymorphism is also called:
Early binding
Dynamic (late) binding
Static binding
Compile-time binding
Answer: B
The method to call is chosen while the program runs, based on the actual object.
Shape Circle
Error