C # - Inheritance Question and Answer

C # - Inheritance Question and Answer
1. Which of the following can be facilitated by the Inheritance mechanism?

    Use the existing functionality of base class.
    Overrride the existing functionality of base class.
    Implement new functionality in the derived class.
    Implement polymorphic behaviour.
    Implement containership.
  • 1, 2, 3
  • 3, 4
  • 2, 4, 5
  • 3, 5
Show Answer
2. Which of the following statements should be added to the subroutine fun( ) if the C#.NET code snippet given below is to output 9 13?

class BaseClass
{
    protected int i = 13;
}
class Derived: BaseClass
{
    int i = 9;
    public void fun()
    {
        // [*** Add statement here ***]
    }
}
  • Console.WriteLine(base.i + " " + i);
  • Console.WriteLine(i + " " + base.i);
  • Console.WriteLine(mybase.i + " " + i);
  • Console.WriteLine(i + " " + mybase.i);
Show Answer
3. Which of the following should be used to implement a 'Has a' relationship between two entities?
  • Polymorphism
  • Templates
  • Containership
  • Encapsulation
Show Answer
4. In an inheritance chain which of the following members of base class are accessible to the derived class members?

    static
    protected
    private
    shared
    public
  • 1, 3
  • 2, 5
  • 3, 4
  • 4, 5
Show Answer
5. Which of the following are reuse mechanisms available in C#.NET?

    Inheritance
    Encapsulation
    Templates
    Containership
    Polymorphism
  • 1, 4
  • 1, 3
  • 2, 4
  • 3, 5
Show Answer
6. Which of the following should be used to implement a 'Like a' or a 'Kind of' relationship between two entities?
  • Polymorphism
  • Containership
  • Templates
  • Encapsulation
Show Answer
7. Which of the following is the correct way to create an object of the class Sample?
  • Declare the existing class as shadows.
  • Declare the existing class as overloads.
  • Declare the existing class as sealed.
  • Declare the existing class as suppress.
Show Answer
8. Which of the following statements are correct about Inheritance in C#.NET?

    A derived class object contains all the base class data.
    Inheritance cannot suppress the base class functionality.
    A derived class may not be able to access all the base class data.
    Inheritance cannot extend the base class functionality.
    In inheritance chain construction of object happens from base towards derived.
  • 1, 2, 4
  • 2, 4, 5
  • 1, 3, 5
  • 2, 4
Show Answer
9. Assume class B is inherited from class A. Which of the following statements is correct about construction of an object of class B?
  • While creating the object firstly the constructor of class B will be called followed by constructor of class A.
  • While creating the object firstly the constructor of class A will be called followed by constructor of class B.
  • The constructor of only class B will be called.
  • The constructor of only class A will be called.
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test