Monday, March 9, 2015

interface c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace inter
{

    public interface operations
    {

        void operation();
        int add();
        int sub();
        //int mult();
    }
    public class math : operations
    {
        private int x1;
        private int y1;

     
        public math(int x, int y)
        {
            x1 = x;
            y1 = y;

        }
        public int add()
        {
            return x1 + y1;
        }
        public int sub()
        {
            return x1 - y1;
        }
        public void operation()
        {
            Console.WriteLine("x1: {0}", x1);
            Console.WriteLine("y1:{0}", y1);
            Console.WriteLine("add:{0}", add());
            Console.WriteLine("sub:{0}", sub());
        }
    }
        public class math2 : operations
        {
            private int a;
            private int b;

            public math2(int c, int d)
            {
                a = c;
                b = d;
            }
            public int mult()
            {
                return a * b;
            }
            public void operation()
            {
                Console.WriteLine("a: {0}", a);
                Console.WriteLine("b:{0}", b);
                Console.WriteLine("add:{0}", mult());
               
            }
        }
   
    class Tester
    {
        static void Main(string[] args)
        {
            math madd = new math(20, 30);
            math2 m2= new math2(10,30);
            madd.operation();
            m2.operation();
            Console.ReadKey();
        }
    }
}



No comments:

Post a Comment