Inheritance



1.
Which of the following can be facilitated by the Inheritance mechanism?

   1. Use the existing functionality of base class.
   2. Overrride the existing functionality of base class.
   3. Implement new functionality in the derived class.
   4. Implement polymorphic behaviour.
   5. Implement containership.
 

  • A) 1,2,3
  • B) 3,4
  • C) 2,4,5
  • D) 3,5
  • E) all of these


2.
 
What will be the size of the object created by the following C#.NET code snippet?

 namespace LazyQuestionsConsoleApplication
{     
   class Baseclass   
     {        
        private int i;         
       protected int j;         
       public int k;   
    }   

  class Derived: Baseclass    
   {        
     private int x;  
     protected int y;      
    public int z;   
  }    
 class MyProgram   
  {        
     static void Main (string[ ] args)  
      {          
        Derived d = new Derived();    
      }   
  } 
}
 

  • A) 24 bytes
  • B) 12 bytes
  • C) 20 bytes
  • D) 10 bytes
  • E) 16 bytes


3. Which of the following should be used to implement a 'Has a' relationship between two entities?  

  • A) Polymorphism
  • B) Inheritance
  • C) Templates
  • D) Containership
  • E) Encapsulation


4. Which of the following are reuse mechanisms available in C#.NET? 1. Inheritance 2. Encapsulation 3. Templates 4. Containership 5. Polymorphism  

  • A) 1,4
  • B) 2,4
  • C) 1,3
  • D) 3,5
  • E) 2,4,5



5. 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.
  • E) The order of calling constructors depends upon whether constructors in class A and class B are private or public.


6. Multiple inheritance is different from multiple levels of inheritance.  

  • A) True
  • B) False


7. An object of a derived class cannot access private members of base class.  

  • A) True
  • B) False


8. The way a derived class member function can access base class public members, the base class member functions can access public member functions of derived class.  

  • A) True
  • B) False


9. There is no private or protected inheritance in C#.NET.  

  • A) True
  • B) False


10. We can derive a class from a base class even if the base class's source code is not available.  

  • A) True
  • B) False


11.
If a base class contains a member function func(), and a derived class does not contain a function with this name, an object of the derived class cannot access func().
 

  • A) True
  • B) False


12. If a base class and a derived class each include a member function with the same name, the member function of the derived class will be called by an object of the derived class  

  • A) True
  • B) False


13. The size of a derived class object is equal to the sum of sizes of data members in base class and the derived class.  

  • A) True
  • B) False


14. Private members of base class cannot be accessed by derived class member functions or objects of derived class.  

  • A) True
  • B) False


15. A class D can be derived from a class C, which is derived from a class B, which is derived from a class A.  

  • A) True
  • B) False


16. There is no multiple inheritance in C#.NET. That is, a class cannot be derived from multiple base classes.  

  • A) True
  • B) False


17. Creating a derived class from a base class requires fundamental changes to the base class.  

  • A) True
  • B) False


18. It is illegal to make objects of one class as members of another class.  

  • A) True
  • B) False


19. what is inheritance ?  

The method of constructing one class from another is called Inheritance.The derived class inherits all the properties and methods from the base class and it can add its own methods also


20. Are constructors and destructors inherited ?  

No


.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions