Click here to Skip to main content
14,981,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MSIL
class Program
    {
        interface math
        {
            void odd();
            void even();
        }
        class test : math
        {
            void math.odd()
            {
Console.WriteLine("number is odd");
            }
            void math.even()
            {
Console.WriteLine("number is odd");
            }
         public void sort(math ob)
            {
                Console.WriteLine("enter number");
                int n = Convert.ToInt32(Console.ReadLine());
                if( n%2==0)
                Console.WriteLine("number is even");
                else
                Console.WriteLine("number is odd");
            }
        }
        static void Main(string[] args)
        {
            math ob = new test();
            test ob1=new test();
            ob1.sort(ob);

            Console.ReadKey();
        }
    }

i have just used a simple example of even odd function to check interface implementation.Is this way of implementing the interface correct?? as the methods declared in interface didnt have any implementation could this have been done without the interface??
Posted
Updated 10-Mar-10 20:06pm
v2

1 solution

<<is this="" way="" of="" implementing="" the="" interface="" correct??

yes,="" is="" correct.="" such="" implementation="" means="" that="" method="" are="" private="" and="" you="" can't="" get="" access="" out="" class,="" only="" throught="" interface.="" for="" example:

<pre="">
test t = new test();
test.odd(); //-compilation error

(test as math).odd(); //OK
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900