About Inheritance
What is multiple inheritance in C# with example
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bikesh SrivastavaPosted Nov 30, 2016, 8:51 AM
MayankPosted Nov 30, 2016, 6:34 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MultipleInheritApplication
{
interface calc1
{
int add(int a, int b);
}
interface calc2
{
int sub(int x, int y);
}
interface calc3
{
int mul(int r, int s);
}
interface calc4
{
int div(int c, int d);
}
class Calculation : calc1, calc2, calc3, calc4
{
public int result1;
public int add(int a, int b)
{
return result1 = a + b;
}
public int result2;
public int sub(int x, int y)
{
return result2 = x - y;
}
public int result3;
public int mul(int r, int s)
{
return result3 = r * s;
}
public int result4;
public int div(int c, int d)
{
return result4 = c / d;
}
class Program
{
static void Main(string[] args)
{
Calculation c = new Calculation();
c.add(8, 2);
c.sub(20, 10);
c.mul(5, 2);
c.div(20, 10);
Console.WriteLine("Multiple Inheritance concept Using Interfaces :\n ");
Console.WriteLine("Addition: " + c.result1);
Console.WriteLine("Substraction: " + c.result2);
Console.WriteLine("Multiplication :" + c.result3);
Console.WriteLine("Division: " + c.result4);
Console.ReadKey();
}
}
}
}
Santhosh KumarPosted Nov 28, 2016, 4:28 AM
using System;
namespace InheritanceApplication
{
class Shape
{
public void setWidth(int w)
{
width = w;
}
public void setHeight(int h)
{
height = h;
}
protected int width;
protected int height;
}
// Base class PaintCost
public interface PaintCost
{
int getCost(int area);
}
// Derived class
class Rectangle : Shape, PaintCost
{
public int getArea()
{
return (width * height);
}
public int getCost(int area)
{
return area * 70;
}
}
class RectangleTester
{
static void Main(string[] args)
{
Rectangle Rect = new Rectangle();
int area;
Rect.setWidth(5);
Rect.setHeight(7);
area = Rect.getArea();
// Print the area of the object.
Console.WriteLine("Total area: {0}", Rect.getArea());
Console.WriteLine("Total paint cost: ${0}" , Rect.getCost(area));
Console.ReadKey();
}
}
}
Total area: 35
Total paint cost: $2450
Rajeesh MenothPosted Nov 21, 2016, 4:47 AM
Ravi PatelPosted Nov 21, 2016, 2:30 AM
Pramod ThakurPosted Nov 21, 2016, 1:48 AM
Shubham KumarPosted Nov 21, 2016, 1:44 AM