Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Inheritance Questions
Method hiding with new: what is printed? 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 { static void Main(string[] args) { Derived2 d = new Derived2(); d.fun(); } } }
Reuse mechanisms in C#.NET: which of the following provide code reuse in typical C# design? 1) Inheritance 2) Encapsulation 3) Templates 4) Containership (composition/aggregation) 5) Polymorphism
Preventing inheritance in C#.NET: which modifier should be applied to a class to disallow deriving from it?
Accessing hidden and base fields: which line should be added so that fun() prints 9 13 for the following code? class BaseClass { protected int i = 13; } class Derived : BaseClass { int i = 9; public void fun() { // [*** Add statement here ***] } }
Combining base-class behavior with derived behavior: which statement should be added so that the output is exactly Welcome to CuriousTab.com! for the following code? class A { public void fun() { Console.Write("Welcome"); } } class B : A { public void fun() { // [*** Add statement here ***] Console.WriteLine(" to CuriousTab.com!"); } }
C#.NET inheritance and accessibility — analyze the following program and choose the valid statements. 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(); } } } Which statements are correct regarding accessibility and constructor behavior in this inheritance setup?
C#.NET objects and memory model — estimate the size of an instance (ignoring object header). 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(); } } } What is the size contribution of the fields in one
Derived
object if each
int
is 4 bytes (ignore header/alignment)?
Object relationships in software design — which construct implements a “Has a” relationship?
C#.NET constructor chaining — predict the output. 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); } } } What will be printed?
Object relationships in software design — which construct implements a “Like a / Kind of” relationship?
C#.NET inheritance accessibility — which base-class members are accessible to derived classes? Choose all that apply among: 1) static 2) protected 3) private 4) shared (VB equivalent of static) 5) public
C#.NET inheritance facts — select the correct statements. A derived class object contains all the base-class data. Inheritance cannot suppress base-class functionality. A derived class may not be able to access all the base-class data. Inheritance cannot extend base-class functionality. During object construction in an inheritance chain, construction happens from base towards derived.
C#.NET constructor order — if class B inherits A, which constructor runs first when creating a B object?
C#.NET — What can inheritance facilitate? Choose the best set.
C#.NET method hiding vs overloading — predict the output. 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 = new Derived(); d.fun(); d.fun(77); } } } What will be printed?
In C++ object-oriented programming, if both a base class and a derived class define a member function with the same name and compatible signature, then calls made on a derived-class object will resolve to the derived version. Is this statement accurate? Provide the most precise judgment.
In C++ access control, private members of a base class cannot be accessed directly by member functions of a derived class, nor by objects of the derived class. Judge the statement.
In C#.NET class inheritance, there is no multiple inheritance of classes (a class cannot derive from more than one base class). Assess the statement.
In C++ object layout, is the size of a derived-class object always equal to the sum of the sizes of the base-class data members and the derived-class data members? Choose the most accurate evaluation.
Concept check: Is multiple inheritance (deriving from more than one base class) the same as multilevel inheritance (a chain Base → Derived → MoreDerived)? Provide the best judgment.
1
2