AITeky Learn

Object-oriented programming

Classes and objects, the four pillars, overloading and overriding, interfaces. 20 questions with model answers.

1. What is the difference between a class and an object? Basic

A class is a blueprint that says what data and behaviour a kind of thing has. An object is one real thing made from that blueprint, with its own values. For example, Car is a class with fields like colour and speed and a method drive(); myCar, a red car going at 40, is an object of it. One class can make many objects.

What the interviewer listens for

  • Class is the blueprint or template
  • Object is an instance with its own values
  • One class, many objects
  • A clear example

Common mistake: Saying they are the same thing, or giving a definition with no example.

They may ask next: Does a class take memory when you define it?

2. What are the four pillars of object-oriented programming? Basic

Encapsulation, abstraction, inheritance and polymorphism. Encapsulation keeps data and the methods that use it together and hides the data behind methods. Abstraction shows only what a user needs and hides how it works. Inheritance lets a class reuse and extend another class. Polymorphism lets one name, such as a method, behave differently depending on the object.

What the interviewer listens for

  • Names all four
  • One line on each
  • An example for at least one

Common mistake: Listing the four names without being able to explain any of them.

They may ask next: Which of the four do you think matters most, and why?

3. What is encapsulation? Give an example. Basic

Encapsulation means keeping an object's data and the methods that work on it in one unit, and not letting outside code change the data directly. In a BankAccount class, balance is private; other code can only call deposit() and withdraw(), which check the amount first. So the balance can never become wrong by accident.

What the interviewer listens for

  • Data and methods together in one unit
  • Data hidden, usually private
  • Access only through methods that check
  • Example such as a bank account

Common mistake: Mixing it up with abstraction without showing the data-hiding part.

They may ask next: What are getters and setters, and are they always a good idea?

These are 3 of the 20 questions. The rest, and practice rounds with Ari, come with Campus Ready.

Sign up free to take the placement tests and see your readiness

It takes a minute with your email. AiTeky Pass (₹999/month or ₹9,999/year) is free for your first 30 days.

We use essential cookies to run the site. With your permission we also set one anonymous ID to count unique visitors, and analytics cookies to see which pages help learners. Cookie notice

Join AiTeky Learn. It's free.

Create a free account to track your progress, save items for later and get study suggestions.

Sign up free Log in