MCQ with answers for (OOP) | Object Oriented Programming | 22316 [ Inheritance] MSBTE
| Subject | subject details | 
|---|---|
| Program: | Diploma in Computer engineering | 
| Program Code | CO | 
| Scheme | I | 
| Semester | 3 | 
| Course: | Object Oriented Programming | 
| Course Code | 22316 | 
1. The ……………. inherits some or all of the properties of the ……….. class.
A) base, derivedB) derived, base
C) derived, initial
D) base, final
  2. A derived class with only one base class is called …………… inheritance.
A)     single
B) multiple
C) multilevel
D) hierarchical
  3. A class can inherit properties from more than one class which is known     as ……….inheritance.
A) single
B) multiple
C) multilevel
D)     hierarchical
A) single
B) multiple
C) multilevel
D) hierarchical
  5. When the properties of one class are inherited by more than one class,     which is called ……… inheritance.
A) single
B) multiple
C)     multilevel
D) hierarchical
  6. When a base class is privately inherited by a derived class public     members of the base class become ………. of the derived class.
A) private     members
B) protected members
C) Public members
D) Not     inherited
  7. When a base class is privately inherited by derived class public members     of the base class can only be accessed by the ……… of the derived class.
A)     non-member functions
B) friend functions
C) member functions
D)     class members
A) protected
B) private
C) public
D) friend
  9. State whether the following statements about inheritance are True or     False.
i) A public member of a class can be accessed by its own objects     using the dot operator.
ii) While inheriting, the private members of     the base class will never become members of its derived class.
A) True,     False
B) False, True
C) True, True
D) False, False
  10. A member declared as ………….. is accessible by the member functions     within its class and any class immediately derived from it.
A)     protected
B) private
C) public
D) friend
  11. When the base class is publicly inherited, public members of the base     class become …………. of the derived class.
A) private members
B)     protected members
C) Public members
D) Not inherited
A) protected
B) private
C) public
D) friend
  13. What will be the order of execution of base class constructors in the     following method of inheritance?
class A: public B, public C {….};
A)     B(); C(); A();
B) C(); B(); A();
C) A(); B(); C();
D) B();     A(); C();
  14. What will be the order of execution of base class constructors in the     following method of inheritance?
class A: public B, virtual public C     {….};
A) B(); C(); A();
B) C(); B(); A();
C) A(); B();     C();
D) B(); A(); C();
  15. While the friend functions and the member functions of a friend class     can have direct access to both the private and protected data, the member     functions of a derived class can directly access only the ………… data.
A)     protected
B) private
C) public
D) friend
  16. In ……………………. inheritance, the constructors are executed in the order of     inheritance.
A) multipath
B) multiple
C) multilevel
D)     hierarchical
  17. In ……………….. inheritance, the base classes are constructed in the order     in which they appear in the deceleration of the derived class.
A)     multipath
B) multiple
C) multilevel
D) hierarchical
  18. ……………….. inheritance may lead to duplication of inherited members from     a ‘grandparent’ base class.
A) multipath
B) multiple
C)     multilevel
D) hierarchical
  19. The member functions of a derived class can directly access only the     ……………….. data.
A) private and protected
B) private and public
C)     protected and public
D) private, protected and public
  20. The friend functions and the member functions of a friend class can     directly access the ………………. data.
A) private and protected
B)     private and public
C) protected and public
D) private, protected     and public
Answers
  1. B) derived, base
2. A) single
3. B) multiple
4. C)     multilevel
5. D) hierarchical
6. A) private members
7. C)     member functions
8. A) protected
9. C) True, True
10. A)     protected
11. C) Public members
12. A) protected
13. A) B();     C(); A();
14. B) C(); B(); A();
15. A) protected
16. C)     multilevel
17. B) multiple
18. A) multipath
19. C) protected     and public
20. A) private and protected
SET -2 (THIS is not in pdf)
    1. What is Inheritance in C++?
a) Wrapping of data into a single     class
b) Deriving new classes from existing classes
c) Overloading     of classes
d) Classes with same names   
Answer: b
Explanation: Inheritance is the concept of OOPs in which new classes are derived from existing classes in order to reuse the properties of classes defined earlier.
    2. How many specifiers are used to derive a class?
a) 1
b) 2
c)     3
d) 4
  
Explanation: There are 3 specifiers used to derive a class. They are private, protected and public.
    3. Which specifier makes all the data members and functions of base class     inaccessible by the derived class?
a) private
b) protected
c)     public
d) both private and protected
  
Explanation: Private access specifier is used to make all the data members and functions of the base class inaccessible.
    4. If a class is derived privately from a base class then     ______________________________
a) no members of the base class is     inherited
b) all members are accessible by the derived class
c)     all the members are inherited by the class but are hidden and cannot be     accessible
d) no derivation of the class gives an error
  
Explanation: Whenever a class is derived, all the members of the base class is inherited by the derived class but are not accessible by the derived class.
      8. What is a virtual function in C++?
a) Any member function of a       class
b) All functions that are derived from the base class
c)       All the members that are accessing base class data members
d) All the       functions which are declared in the base class and is       re-defined/overridden by the derived class
    
Explanation: Virtual function is a function that is declared inside the base class and is re-defined inside the derived class.
      9. Which is the correct syntax of declaring a virtual function?
a)       virtual int func();
b) virtual int func(){};
c) inline virtual       func();
d) inline virtual func(){};
    
Explanation: To make a function virtual function we just need to add virtual keyword at the starting of the function declaration.
        13. Which statement is incorrect about virtual function.
a) They         are used to achieve runtime polymorphism
b) They are used to hide         objects
c) Each virtual function declaration starts with the         virtual keyword
d) All of the mentioned
      
Explanation: Virtual function are used to achieve runtime polymorphism by calling the right function during runtime. Their declaration starts with a virtual keyword.
        14. The concept of deciding which function to invoke during runtime is         called ______________________
a) late binding
b) dynamic         linkage
c) static binding
d) both late binding and dynamic         linkage
      
Explanation: The concept of deciding which function to invoke during runtime is called late binding or dynamic linkage. Late binding because function binding to the object is done during runtime. Dynamic linkage because this binding is done during runtime.
        15. What is a pure virtual function?
a) A virtual function defined         inside the base class
b) A virtual function that has no definition         relative to the base class
c) A virtual function that is defined         inside the derived class
d) Any function that is made virtual
      
Explanation: A virtual function that has no definition relative to the base class is called a pure virtual function.
 
    
Comments
Post a Comment