can you overload a method of class A in Class B if it is
derived class of A?If it is yes tell me how is it possible?

Answer Posted / lalit pradhan

namespace Test
{
class Program
{
static void Main(string[] args)
{
A a = new A();
a.Method();

B b = new B();
b.Method("From B");

Console.ReadKey();
}
}

class A
{
public void Method()
{
Console.WriteLine("From A");
}
}

class B : A
{
public void Method(string s)
{
Console.WriteLine(s);
}
}
}

Is This Answer Correct ?    15 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is dynamic dispatch?

544


What is datasource c#?

484


Why delegates are safe in c#?

449


Can you mark static constructor with access modifiers?

544


What is dataset and dataadapter in c#?

492






What are the 2 broad classifications of data types available in c#?

460


How can we sort the elements of the array in descending order?

522


What is the use of properties window?

492


How to override a function in c#?

535


What are the advantages of using c#?

500


Why do we need to call CG.SupressFinalize?

546


Can we override interface methods in c#?

469


What is null propagation c#?

500


How do I develop c# apps?

516


Does c# support a variable number of arguments?

601