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() { 
        
      } 
};

Related Posts