Q) The OOPs concept in C++, exposing only necessary information to users or clients is known as
- Abstraction
- Encapsulation
- Data hiding
- Hiding complexity
Answer: 1
Q) Which of the following is an abstract data type?
- Class
- Int
- String
- Double
Answer: 1
Q) Hiding the complexity is known as
- Abstraction
- Encapsulation
- Data hiding
- 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
- class Cat: public Animal
- class Animal: public Cat
- Both are correct way
- None is correct way
Answer: 1
Q) In a class, encapsulating an object of another class is called
- Composition
- Inheritance
- Encapsulation
- 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() {
}
};