LearnFrenzy
Sign in Take a free test

C++ Programming · Topic 15 of 27

Abstraction

  • 4 exercises
  • 60 questions
  • ~60 min
  • Answers explained

Interview Questions

Abstraction · Study material

C++ Abstraction – Interview Questions

1. What is abstraction?

Exposing only the essential operations of something and hiding its implementation details.

2. What is the difference between abstraction and encapsulation?

Abstraction decides what to show (the interface); encapsulation hides and protects the internals (bundling data with functions and restricting access).

3. How do you achieve abstraction in C++?

Classes with access specifiers, abstract classes/interfaces, header files, templates and concepts, and functions.

4. What is data abstraction?

Representing data by its operations rather than its storage – for example a Date class with add_days() instead of three public ints.

5. What is an abstract data type?

A type defined by its operations and their behaviour, independent of representation: stack, queue, map, set.

6. What is control abstraction?

Hiding sequences of steps behind a function or construct – functions, loops, algorithms like std::sort.

7. What is an interface in C++?

C++ has no interface keyword; an interface is a class with only pure virtual functions and a virtual destructor.

8. What does "program to an interface" mean?

Depend on abstract types (or concepts) rather than concrete classes, so implementations can be swapped.

9. What is the pimpl idiom?

Keeping private members in a separate Impl struct accessed through a pointer, so the header stays stable and users need not recompile when the implementation changes.

10. What are the costs of pimpl?

A heap allocation per object, an extra indirection per access and some boilerplate (destructor and moves defined in the source file).

11. How is RAII a form of abstraction?

It hides the need to release resources: acquisition happens in the constructor, release in the destructor, automatically on every path.

12. What is a leaky abstraction?

An abstraction whose hidden details still affect users, forcing them to understand the implementation.

13. What is the zero-overhead principle?

Abstractions you do not use cost nothing, and those you use are as efficient as hand-written code.

14. Is a class with all public data members an abstraction?

Only a weak one: it names a concept but exposes its representation, so users depend on it.

15. How do templates provide abstraction?

They write algorithms and containers once, independent of the element type, with static dispatch.

16. What do C++20 concepts add?

Named, checked requirements on template parameters – an explicit compile-time interface with clear error messages.

17. Why are getters and setters for every field a poor abstraction?

They expose the representation one field at a time, letting callers depend on it and bypass the class's rules.

18. Can abstraction hurt performance?

Run-time abstraction (virtual calls, pimpl) has small costs; compile-time abstraction (templates, inline functions) usually has none.

19. What is the dependency inversion principle?

High-level modules should depend on abstractions, not on low-level modules; both depend on the abstraction.

20. Give a real-world C++ library example of abstraction.

Iterators: algorithms like std::find work on vectors, lists, arrays and streams because they use the iterator abstraction, not the container.

Ready to test your Programming?

Timed online tests with instant scores and explanations.

About this section

About C++ Programming

C++ adds object-oriented programming, templates and the powerful Standard Template Library (STL) to C. It powers game engines, browsers, trading systems and most competitive programming. This section takes you from basic syntax to classes, inheritance, polymorphism, modern C++ (C++11 to C++23) and the STL – every concept with runnable examples and practice questions checked on a real compiler.

Why it matters

  • OOP concepts – classes, inheritance, polymorphism, encapsulation – are asked in almost every interview
  • C++ with the STL is the most popular language for competitive programming and DSA rounds
  • Questions on constructors, virtual functions, references and smart pointers decide technical rounds
  • Modern C++ skills are in demand at product companies, fintech and game studios

Who it is for

  • School students (Class 11–12 computer science with C++) preparing for board exams and practicals
  • College students (B.Tech, BCA, MCA) learning OOP and data structures for semester exams and labs
  • Freshers preparing for placements, coding tests and C++ technical interviews
  • Competitive programmers who want to master the STL

What every topic gives you

  • Study material in five tabs: concepts with runnable examples, coding techniques, programs, interview questions and a cheat sheet
  • MCQs that check your understanding of every concept
  • "Predict the output" puzzles – the trickiest part of written tests
  • "Find the error" programs that train you to spot bugs quickly
  • Complete programs with solutions and real output, verified on a compiler

Asked in

  • Campus placements
  • Product company interviews
  • Coding rounds & DSA
  • Competitive programming
  • GATE CS
  • University exams

How to use this section

  1. Read the study material of a topic and run the examples yourself.
  2. Practise the four exercises – MCQs, output, errors, programs – and read every explanation.
  3. Test yourself with the timed online test, then revise the topics you got wrong.

Search LearnFrenzy

Esc

Quick links