Interview Q&A / Object-Oriented Programming

INTERVIEW Q&A · 69 QUESTIONS

Object-Oriented Programming interview questions

The four pillars, interfaces, abstract classes and design basics.

  1. What is the difference between compile-time and runtime polymorphism?

    Compile-time (static) polymorphism is resolved by the compiler using the declared types, mainly through method overloading. Runtime (dynamic) polymorphism is resolved by the JVM using the actual object, through method overriding and dynamic dispatch. Fields, static methods and private methods are never resolved at runtime.

    AdvancedIn-depth4 min read
  2. Predict the output: a parent reference holds a child object that hides the parent's field. Which value do you get?

    Methods are chosen by the object's real type, but fields are chosen by the reference type. So p.name gives the parent's value while p.get() runs the child's method.

    AdvancedQuick answer1 min read