1
Reply

Problem in Interfaces (polymorphism) C#

Mohsan

Mohsan

May 5 2009 1:10 AM
2.4k

hi.

i have two classes which have some common methods like funcA(), funcB()

and some methods are only related to its class...

what i did is made interface of TestInterface

public interface TestInterface
{
   
void funcA()
   
void funcB()

}



public class ClassA : TestInterface
{
 
public  void funcA()
   
{
     
Console.WriteLine("This is ClassA FuncA()");
   
}
 
public  void funcB()
   
{
     
Console.WriteLine("This is ClassA FuncB()");
   
}
 
public void myFuncA()
   
{
     
Console.WriteLine("This is My Own Function A");
   
}

}

public class ClassB : TestInterface
   
{
     
public  void funcA()
       
{
         
Console.WriteLine("This is ClassB FuncA()");
       
}
     
public  void funcB()
       
{
         
Console.WriteLine("This is ClassB FuncB()");
       
}
     
public void myFuncB()
       
{
         
Console.WriteLine("This is My Own Function B");
       
}

   
}



public static void main()
{
 
TestInterface test = new ClassA();
 test
.funcA();
}


as u see in above two classes. i have two functions myFuncA() and myFuncB() are not part of interface. they only belongs to their own class.

how can i call them from the main method. where i am creating object of TestInterface and initializing it with some child class.???



Answers (1)