- The concept of inheritance enables C++
to pass arguments to objects of classes
- to create new classes from existing classes
- to improve data hiding
- to support abstraction
- What is the advantage of using inheritance in C++?
- Facilitates creation of class libraries
- Enables reuse of existing code
Enhances reliability of the code
- All the above
Through inheritance, it is possible to inherit from a class
- only data members
- only members functions
- any members as we desire
- only functions declared as friend
- In the class definition
- class M : visibility-mode N
- {
- members of M
- };
- the visibility-mode
- must be blank
- must be public
must be private
- may be blank, public or private
- Consider the code segment, The derived class C would contain the members ?
- class A
- {
- private : int a ; public : int b ; protected : int c ;
- };
- class B : A { };
- class C : public B { };
- a, b and c
- b and c only
b only
- none
Which of the following statements is TRUE, when a derived class D inherits a base class B using protected specifier?
- public members of B become protected members of D
- public members of B become public members of D
- public members of B become private members of D
- public members are not inherited
- Which of the following functions can have access to the protected data of a class?
- A function that is friend of the class
- A member function of a class declared friend of the class
A member function of a derived class
- All the above
- The use of scope resolution operator in inheritance enables us
- to restrict the visibility of data members
to determine the base class of a derived class
- to specify a particular class
- to make a private member inheritable
- The process of a class inheriting attributes from several classes is known as
multilevel inheritance
- multiple inheritance
- multipath inheritance
- hybrid inheritance
- A class D is privately derived from class B. An object of D in the main function can access
- public members of B
- private members of D
protected members of B
- public members of D
The following examples show that the class C is derived from classes A and B. Which one of them is legal?
- class C : private A, public B
- class C :: private A, public B
- class C : public A : public B
- class C: class A, B
- class C: private A, public B;
- Consider the following code: What happens when we compile this code?
- class A { };
- class B : A { };
- Will not compile because the body of A is empty
- Will not compile because the body of B is empty
- Will not compile because the visibility mode for A is not specified
- Will compile successfully
- Which one of the following statements is FALSE?
- If no constructors are declared for the derived class, the objects of the derived
- class will use the constructors in the base class
- There may be situations where we may have to define a class which will never be used to create objects
- It is legal to make objects of one class as members of another class.
- Consider the following class definition with inheritance: The order of execution of constructors will be:
- class A : public B, virtual public C
- {
- };
A ( ), B ( ), C ( )
- C ( ), B ( ), A ( )
- B ( ), C ( ), A ( )
- A ( ), C ( ), B ( )
- Consider the following class.We wish to define the constructor function using an initialization list. Which one of the following is the legal constructor function?
- class ABC
- {
- int a; int b;
- public : constructor function
- };
- ABC (int x, int y): a (x), b(y) { }
- ABC (int x, int y): b (x), a(x+y) { }
- ABC (int x, int y): a (x), b(a*y) { }
- All of the Above
Answers:
- to create new classes from existing classes
- All the above
- any members as we desire
- may be blank, public or private
- none
- public members of B become protected members of D
- All the above
- to specify a particular class
- multiple inheritance
- public members of D
- class C : private A, public B
- Will compile successfully
- Deriving one class from another requires fundamental changes to the base class.
- A ( ), B ( ), C ( )
- All the above
You must log in to post a comment.