ProgrammingEasyTCS NQT · Infosys interview pattern
A method call such as shape.area() runs different code depending on whether shape refers to a Circle or a Square object at run time. Which OOP feature is this?
- A. Encapsulation
- B. Compile-time polymorphism (method overloading)
- C. Runtime polymorphism (dynamic dispatch through overriding)
- D. Data abstraction through access specifiers
Correct answer: C. Runtime polymorphism (dynamic dispatch through overriding)
Choosing the overridden method from the object’s actual class at run time is runtime polymorphism. Overloading is resolved at compile time from the argument types, and encapsulation is about bundling and hiding data.
More OOP with C++ and Java questions
- A Java class declares only the constructor Account(String id) and no other constructor. What happens with the statement new Account()?
- What is printed? java int x = 5; x = x++ + ++x; System.out.print(x);
- What is printed? cpp class A { public: int x; A(int v) : x(v) {} }; int main() { A a(5); A b = a; b.x = 9; cout << a.x << b.x; }
- Which line fails to compile? java abstract class Shape { abstract double area(); } class Sq extends Shape { double area() { return 4; } }…
- What is printed? java class K { K() { this(5); System.out.print("A"); } K(int x) { System.out.print("B" + x); } } // in main: new K();
- Which line fails to compile? java final int[] arr = {1, 2, 3}; arr[0] = 10; // L1 arr = new int[3]; // L2 System.out.print(arr[0]); // L3