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 are the four pillars of object-oriented programming?

    Encapsulation (keep data and the code that uses it together, and hide the inside), abstraction (show only what matters), inheritance (reuse and extend a parent class) and polymorphism (one interface, many behaviours).

    BeginnerIn-depth2 min read
  2. What is a constructor, and what is constructor chaining?

    A constructor is a special method with the class's name and no return type that runs when an object is created, to set its starting state. Constructor chaining is one constructor calling another, either in the same class with this(...) or in the parent class with super(...), so setup code is written once.

    BeginnerIn-depth3 min read
  3. What is encapsulation, and how do access modifiers help achieve it?

    Encapsulation means keeping an object's data and the methods that change it together, and hiding the data so outside code can only change it through controlled methods. In Java, access modifiers (private, default, protected, public) decide who can see each member, and making fields private with validated methods is the usual way to encapsulate.

    BeginnerIn-depth3 min read
  4. What is the difference between method overloading and method overriding?

    Overloading means several methods in the same class share a name but take different parameters, and the compiler picks one. Overriding means a subclass gives its own version of a method it inherited, with the same signature, and the JVM picks the version at runtime based on the actual object.

    BeginnerIn-depth3 min read
  5. Is encapsulation the same as data hiding?

    Not exactly. Encapsulation bundles data and the methods that work on it into one unit. Data hiding is the part where the fields are made private so outsiders can only use the safe methods.

    BeginnerQuick answer1 min read
  6. What are the types of inheritance, and which does Java support through classes?

    Single, multilevel, hierarchical, multiple and hybrid. Java supports the first three with classes; multiple inheritance of classes is not allowed, but a class can implement many interfaces.

    BeginnerQuick answer1 min read
  7. 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
  8. What is the difference between abstraction and encapsulation?

    Abstraction decides what to show: it exposes a simple view and hides complexity. Encapsulation decides how to protect: it bundles data with methods and restricts access to it.

    BeginnerQuick answer1 min read