Skip to content

MCQs – C++ OOPs


Q) The OOPs concept in C++, exposing only necessary information to users or clients is known as
  1. Abstraction
  2. Encapsulation
  3. Data hiding
  4. Hiding complexity

Answer: 1


Q) Which of the following is an abstract data type?
  1. Class
  2. Int
  3. String
  4. Double

Answer: 1


Q) Hiding the complexity is known as
  1. Abstraction
  2. Encapsulation
  3. Data hiding
  4. Composition

Answer: 2

Recommended to read the interview question- what is abstraction in java? 


Q) For Cat and Animal class, correct way of inheritance is
  1. class Cat: public Animal
  2. class Animal: public Cat
  3. Both are correct way
  4. None is correct way

Answer: 1



Q) In a class, encapsulating an object of another class is called
  1. Composition
  2. Inheritance
  3. Encapsulation
  4. None

Answer: 1

In simple word, if a class contains an object of another class as a data member, then it is known as composition. For example,
Class Y, have a class X’s object as data member. Means, Y is composed of X.

class X {
  public:
     void f1() { 
        
      } 
};
class Y{
	X obj;//class object as a data member
public:
     void f2() { 
        
      } 
};

Another example, we can take that a house is composed of windows, door and bricks etc. So, class House will look like below

class Door {
  
};
class Windows {
  
};
class Bricks {
  
};
class House{
	Door _d;
	Windows _w;
	Bricks _b;

public:
     void showHouse() { 
        
      } 
};

Pages: 1 2 3


Published inMCQ-C++

7 Comments

  1. Swathi

    Inheritance

  2. Thanks for your question Nadeem. Yes hiding the complexity whatever the ways you hide is encapsulation and it is an implementation level concepts. Abstraction is a design level concept in which you ONLY decide what essential details to expose to user/clients and ENCAPSULATE the rest.

    As a side note you might be familiar: wrapping a class field withing a method is just an EXAMPLE of encapsulation.

    Hope this clears you. You can ask further questions and I’ll be happy to answer.
    -Rakesh

  3. Attiqa nadeem

    are u sure / right answer is encapuslation bcoz abstraction also hide the internal info with clients /

  4. Thanks Rydzu for pointing out the typo. Updated it.

  5. Rydzu

    Q) Which C++ oops feature is related to re-usability?
    Answer should be B

  6. Hi, Thanks for the response. Please read the post about abstraction in java oop .

    Abstraction in java: Provide only necessary information to client.

    Encapsulation: Whatever the way we apply to hide information is encapsulation.

    “In fact, implementation of encapsulation is Abstraction”

  7. BABAN KALLAPPA AARGU

    hiding a complexity is known as Abstraction not a Encapsulation

Comments are closed.