Abstraction and Interfaces

Last Updated :
Discuss
Comments

Question 1

How do pure virtual functions help achieve abstraction in C++?

  • A

    Do not help in any way

  • B

    Allow the class to show only the interface, not the implementation

  • C

    Help in combining data and functions together

  • D

    Abstraction is not applicable to classes

Question 2

.Which of the following best describes the concept of abstraction in object-oriented programming?
 

  • A

    Restricting access to certain class members from outside the class
     

  • B

    Representing essential features without including background details

  • C

    Combining data and methods into a single unit
     

  • D

    Allowing multiple classes to inherit from a single superclass
     

Question 3

What is the primary purpose of abstraction in OOP? 

  • A

    Treating objects of different classes uniformly

  • B

    Simplifying complex systems by focusing on essential characteristics

  • C

    Defining attributes and behaviors of objects

  • D

    Protecting data using access modifiers

Question 4

Which of the following is NOT true about interfaces?

  • A

    Can contain default methods


  • B

    Can contain constructors

  • C

    Can be implemented by multiple classes

  • D

    Can contain static methods

Question 5

Which of the following best describes abstraction?


  • A

    Hiding implementation details and showing only relevant information to the users.

  • B

    Binding both data members and member functions into a single unit.

  • C

    Accessing data members and member functions of one class by other

  • D

    All of the above

Question 6

What would be the output of the following code snippet?

C
#include
Using namespace std;

class implementAbstraction{
private:
   int a,b;
   void set(int x,int y)
   {
        a=x;
        b=y;
    }
    void display()
    {
       cout<<”a=”<<a<<endl;
       cout<<”b=”<<b<<endl;
    }
  };
  int main()
  { 
    implementAbstraction obj;
    obj.set(10,20);
    obj.display();
    return 0;
   }


  • A

    a = 10, b = 20

  • B

    a = 20, b = 10

  • C

    Compilation Error

  • D

    Runtime Error

Question 7

Which of the following best supports abstraction in C++?

  • A

    Pointers

  • B

    Access specifiers and pure virtual functions

  • C

    Constructors

  • D

    Inheritance

Question 8

Which access specifier is commonly used to hide data in abstraction?

  • A

    Public

  • B

    Private

  • C

    Protected

  • D

    Any of these

Question 9

What is the major difference in abstraction and encapsulation?

  • A

    Abstraction hides implementation encapsulation binds data and function together.

  • B

    Abstraction uses private members and encapsulation uses public members.

  • C

    Encapsulation hides logic and abstraction binds data.

  • D

    There is no difference

Question 10

What is Abstraction?

  • A

    Hiding complexity, showing only essential parts

  • B

    Creating multiple objects

  • C

    Inheriting properties

  • D

    Encapsulating data

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion