The Following C Code Is Run On Single Level Of Inheritance What #358
The following C# code is run on single level of inheritance. What will be the Correct statement in the following C# code?</p> <pre><code class="language-csharp" line="1"> class sample { int i = 10; int j = 20; public void display() { Console.WriteLine("base method "); } } class sample1 : sample { public int s = 30; } class Program { static void Main(string[] args) { sample1 obj = new sample1(); Console.WriteLine("{0}, {1}, {2}", obj.i, obj.j, obj.s); obj.display(); Console.ReadLine(); } } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs108 CSharp. It can also be found in gs gs108 Object Oriented Concepts - Inheritance Implementation - Quiz No.1.
The following C# code is run on single level of inheritance. What will be the Correct statement in the following C# code?
class sample { int i = 10; int j = 20; public void display() { Console.WriteLine("base method "); } } class sample1 : sample { public int s = 30; } class Program { static void Main(string[] args) { sample1 obj = new sample1(); Console.WriteLine("{0}, {1}, {2}", obj.i, obj.j, obj.s); obj.display(); Console.ReadLine(); } }
10, 20, 30 base method
10, 20, 0
compile time error
base method