An interface has got four Interface methods (m1,m2,m3,m4) and implement these interface methods as follows.
Implement m1() & m2() in base class
Implement m3() & m4() in derived class

 Posted by Self-Innovator on 1/12/2015 | Category: OOPS Interview questions | Views: 1153 | Points: 40
Answer:

Declare an interface class
 interface myInterface

{
void m1();
void m2();
void m3();
void m4();
}

Declare Base class which inherits an Interface Class

public class mybaseClass:myInterface
{
public void m1()
{
Console.WriteLine("m1");
}
public void m2()
{
Console.WriteLine("m2");
}
public virtual void m3()
{ }

public virtual void m4()
{ }
}

Declare a Derived class which Inherits Base class & Interface Class

public class derivedClass : mybaseClass, myInterface
{

public override void m3()
{
Console.WriteLine("m3");
}
public override void m4()
{
Console.WriteLine("m4");
}
}


class Program

{
static void Main(string[] args)
{
derivedClass dc = new derivedClass();
dc.m1();
dc.m2();
dc.m3();
dc.m4();
Console.ReadKey();
}
}


Source: Mindtree Interview Question | Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response