LearnFrenzy
Sign in Take a free test

Abstraction · Exercise 1 of 4

Abstraction Abstraction MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on abstraction in C++: interface vs implementation, abstraction vs encapsulation, abstract data types, interfaces, templates, pimpl and RAII. Pick an option to check your answer instantly.

Question 1 Easy

Which statement best describes abstraction?

A Making every member public
B Showing what an object does while hiding how it does it
C Writing code in assembly
D Creating many objects of a class
Question page & discussion
Question 2 Easy

Which pairing is correct?

A Abstraction: private members; encapsulation: interfaces
B Abstraction: choosing what users see; encapsulation: bundling data with functions and restricting access
C They are identical
D Abstraction is only for templates
Question page & discussion
Question 3 Easy

What defines an abstract data type such as a stack?

A Its memory layout
B Its operations and their behaviour, independent of representation
C The compiler used
D Its file name
Question page & discussion
Question 4 Easy

C++ has no interface keyword. How is an interface usually expressed?

A A struct with only data members
B A class with only pure virtual functions and a virtual destructor
C A namespace
D A macro
Question page & discussion
Question 5 Easy

Which of these does not provide abstraction in C++?

A Abstract classes
B Header files declaring functions
C Templates
D Making all data members public
Question page & discussion
Question 6 Medium

A ReportService takes a Storage& (abstract) instead of a MySqlStorage&. What is the main benefit?

A It runs faster
B Any Storage implementation – a test double, a file store – can be used without changing ReportService
C It avoids virtual functions
D It uses less memory
Question page & discussion
Question 7 Medium

What is the main purpose of the pimpl idiom?

A Faster function calls
B Hiding private members from the header, so implementation changes do not force users to recompile
C Avoiding the heap
D Making classes copyable
Question page & discussion
Question 8 Hard

A class holds std::unique_ptr<Impl> with Impl only declared in the header. Where must its destructor be defined?

A Inline in the header with = default
B In the source file, after Impl is fully defined
C Nowhere – it is not needed
D In a base class
Question page & discussion
Question 9 Easy

What does RAII hide from the user of a class like std::lock_guard or std::ifstream?

A The type of the resource
B The need to release the resource manually – the destructor does it on every path
C The size of the object
D The constructor
Question page & discussion
Question 10 Medium

What is a "leaky abstraction"?

A A memory leak
B An abstraction whose hidden details still affect users, so they must understand the implementation
C A class without a destructor
D A template with errors
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links