Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Inheritance Questions
What will be the output of the C#.NET code snippet given below? namespace CuriousTabConsoleApplication { class Baseclass { public void fun() { Console.Write("Base class" + " "); } } class Derived1: Baseclass { new void fun() { Console.Write("Derived1 class" + " "); } } class Derived2: Derived1 { new void fun() { Console.Write("Derived2 class" + " "); } } class Program { public static void Main(string[ ] args) { Derived2 d = new Derived2(); d.fun(); } } }
Which of the following are reuse mechanisms available in C#.NET? Inheritance Encapsulation Templates Containership Polymorphism
How can you prevent inheritance from a class in C#.NET?
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 ***] } }
Which statement will you add in the function fun() of class B, if it is to produce the output "Welcome to CuriousTab.com!"? namespace CuriousTabConsoleApplication { class A { public void fun() { Console.Write("Welcome"); } } class B: A { public void fun() { // [*** Add statement here ***] Console.WriteLine(" to CuriousTab.com!"); } } class MyProgram { static void Main (string[ ] args) { B b = new B(); b.fun(); } } }
Which of the following statements are correct about the C#.NET code snippet given below? namespace CuriousTabConsoleApplication { class index { protected int count; public index() { count = 0; } } class index1: index { public void increment() { count = count +1; } } class MyProgram { static void Main(string[] args) { index1 i = new index1(); i.increment(); } } } count should be declared as public if it is to become available in the inheritance chain. count should be declared as protected if it is to become available in the inheritance chain. While constructing an object referred to by i firstly constructor of index class will be called followed by constructor of index1 class. Constructor of index class does not get inherited in index1 class. count should be declared as Friend if it is to become available in the inheritance chain.
What will be the size of the object created by the following C#.NET code snippet? namespace CuriousTabConsoleApplication { 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(); } } }
Which of the following should be used to implement a 'Has a' relationship between two entities?
Which of the following statements is correct about the C#.NET program given below? namespace CuriousTabConsoleApplication { 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); } } }
Which of the following should be used to implement a 'Like a' or a 'Kind of' relationship between two entities?
In an inheritance chain which of the following members of base class are accessible to the derived class members? static protected private shared public
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.
Assume class B is inherited from class A. Which of the following statements is correct about construction of an object of class B?
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.
Which of the following is correct about the C#.NET snippet given below? namespace CuriousTabConsoleApplication { class Baseclass { public void fun() { Console.WriteLine("Hi" + " "); } public void fun(int i) { Console.Write("Hello" + " "); } } class Derived: Baseclass { public void fun() { Console.Write("Bye" + " "); } } class MyProgram { static void Main(string[ ] args) { Derived d; d = new Derived(); d.fun(); d.fun(77); } } }
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
Private members of base class cannot be accessed by derived class member functions or objects of derived class.
There is no multiple inheritance in C#.NET. That is, a class cannot be derived from multiple base classes.
The size of a derived class object is equal to the sum of sizes of data members in base class and the derived class.
Multiple inheritance is different from multiple levels of inheritance.
1
2