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 == and equals() in Java?

    == compares references for objects (are they the same object?) and values for primitives. equals() compares content, but only if the class overrides it; the default version behaves like ==.

    BeginnerQuick answer1 min read
  2. What is the difference between a class and an object?

    A class is a blueprint that describes the fields and methods something will have. An object is one real instance built from that blueprint, with its own values stored in memory.

    BeginnerQuick answer1 min read
  3. What happens in memory when you write new Student("Asha") in Java?

    new allocates memory for the object on the heap, sets fields to default values, runs the constructor, and returns a reference. The variable on the stack holds only that reference.

    IntermediateQuick answer1 min read
  4. What is the difference between a shallow copy and a deep copy of an object?

    A shallow copy duplicates the object but shares the objects it refers to. A deep copy duplicates the whole graph, so the copy shares nothing with the original.

    IntermediateQuick answer1 min read