C# Programming - Inheritance - Discussion
Discussion Forum : Inheritance - General Questions (Q.No. 6)
6.
What will be the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
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();
}
}
}
Discussion:
28 comments Page 3 of 3.
Rajat said:
1 decade ago
Here the new keyword means derived class is calling the hidden function of base class.
Arvind said:
1 decade ago
The answer should be Derived 2, the access specifier doesn't put any difference.
Mahdi said:
1 decade ago
Of course, the output should be "Derived2 class".
Harika said:
4 years ago
Sealed key word stops the inheritance execution.
(1)
Ishwar said:
9 years ago
Virtual Keyword are required in base class.
Ankita Bhagat said:
2 years ago
Yes, the Answer is Base class.
Api said:
1 decade ago
Thanks chandrashekar.
Ipsita said:
1 decade ago
What is new here?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers