Monday, 5 November 2012

Program for Implementation of multiple interface


using System;
interface Addition { int Add(); }
interface Multiplication { int Mul(); }
class Computation : Addition , Multiplication
{
 int x,y;
 public Computation(int x,int y)
 {
  this.x = x;
  this.y = y;
 }
 public int Add() {  return x+y;  }
 public int Mul() {  return x*y;  }
}
class InterfaceTest
{
 static void Main()
 {
  Computation c = new Computation(10,20);
  Addition add = (Addition)c;
  Console.WriteLine("Sum = "+add.Add());
  Multiplication mul = c as Multiplication;
  Console.WriteLine("Product = "+mul.Mul());
  Console.ReadKey();
 }
}

Output:-


No comments:

Post a Comment