How can we invoke a method being defined inside a Base Class (Abstract class) without the Derived class being inheriting it?

 Posted by Niladri.Biswas on 7/30/2012 | Category: C# Interview questions | Views: 1658 | Points: 40
Answer:

We can do so if we declare the method as static. Then by using Classname.MethodName() we can invoke it.

Example:

class Program

{
static void Main(string[] args)
{
MyBase.Hello();

Console.ReadKey();
}

}

public abstract class MyBase
{
public static void Hello()
{
Console.WriteLine("Hello");
}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response