⚡ Play a quiz
HomeLearnCS Core › OOPs Concepts
CS Core · 3 lessons

Object-Oriented Programming Concepts

Object-oriented programming is asked about in nearly every fresher interview, and answered badly in most of them — usually as four memorised definitions. The definitions are the easy part. What interviewers are listening for is whether you can say what each pillar actually buys you, and when it costs more than it gives.

▶ Start with The four pillars
Lessons
3
Read time
23 m
Practice problems
0
Track
CS Core

Lessons in order

What you will be able to do

  • Encapsulation hides state so invariants are enforced in exactly one place.
  • Inheritance is permanent, compile-time coupling to a parent's internals.
  • Dynamic dispatch defers the choice of implementation to runtime via a vtable lookup.

Quiz yourself on OOPs Concepts

Reading is not recall. Take a timed quiz on this topic solo, or share a room code and battle friends on it.

⚡ Start the OOPs Concepts quiz

Frequently asked questions

What is the difference between abstraction and encapsulation?

Encapsulation hides data behind methods so invalid states cannot be created from outside. Abstraction hides how something is implemented behind a contract, so the implementation can change without affecting callers.

What is the difference between method overloading and overriding?

Overloading is several methods with the same name but different parameter lists, resolved by the compiler. Overriding is a subclass replacing a parent method with the same signature, resolved at runtime from the actual object type.

Can you achieve abstraction without an interface?

Yes. An abstract class provides abstraction plus shared state and implementation. An interface is preferred when you only need the contract, because a class can implement many interfaces but extend only one class.

Why is composition preferred over inheritance?

Composition couples to a contract rather than to a parent's implementation, can be changed at runtime, avoids the fragile base class problem, and lets capabilities combine without a class per combination.

When is inheritance the right choice?

When the subclass genuinely is a kind of the parent and can be substituted for it everywhere, and when there is real shared state and behaviour to inherit rather than just code you want to reuse.

What is the fragile base class problem?

Changing a base class can silently break subclasses that depended on its internal behaviour, even though the subclasses were not modified and the change looked safe in isolation.

Other topics in CS Core