Exercise: Inheritance

Questions for: Inheritance

An object of a derived class cannot access private members of base class.
A:
True
B:
False
C:
D:
Answer: A
The private members of the base class are never accessible outside the class.
Multiple inheritance is different from multiple levels of inheritance.
A:
True
B:
False
C:
D:
Answer: A
Multiple inheritance means deriving a class from more than one classes. On the other hand, multiple levels of inheritance means a class has been derived from a base class and the base class itself has been derived from another base class. Multiple inheritance is not permitted in C#.NET.
Which of the following statements is correct about the C#.NET program given below?
namespace ExamAdept
{
    class Baseclass
    { 
        int i;
        public Baseclass(int ii)
        {
            i = ii;
            Console.Write("Base "); 
        } 
    } 
    class Derived : Baseclass
    {
        public Derived(int ii) : base(ii)
        {
            Console.Write("Derived ");
        } 
    } 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            Derived d = new Derived(10);
        } 
    } 
}
A:
The program will work correctly only if we implement zero-argument constructors in Baseclass as well as Derived class.
B:
The program will output: Derived Base
C:
The program will report an error in the statement base(ii).
D:
The program will work correctly if we replace base(ii) with base.Baseclass(ii).
Answer: E
No answer description is available. Let's discuss.
Assume class B is inherited from class A. Which of the following statements is correct about construction of an object of class B?
A:
While creating the object firstly the constructor of class B will be called followed by constructor of class A.
B:
While creating the object firstly the constructor of class A will be called followed by constructor of class B.
C:
The constructor of only class B will be called.
D:
The constructor of only class A will be called.
Answer: B
No answer description is available. Let's discuss.
Which of the following statements are correct about Inheritance in C#.NET?
  1. A derived class object contains all the base class data.
  2. Inheritance cannot suppress the base class functionality.
  3. A derived class may not be able to access all the base class data.
  4. Inheritance cannot extend the base class functionality.
  5. In inheritance chain construction of object happens from base towards derived.
A:
1, 2, 4
B:
2, 4, 5
C:
1, 3, 5
D:
2, 4
Answer: C
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz