38
1
using System;
2
namespace Application {
3
// Base class Cost
4
public class Shape {
5
6
public void setSide(int s) {
7
side = s;
8
}
9
protected int side;
10
}
11
//interface
12
public interface Cost {
13
int getCost(int area);
14
}
15
// Derived class, using Interface and Base class
16
class square: Shape, Cost {
17
//methods in derived class
18
public int getArea() {
19
return (side * side);
20
}
21
public int getCost(int area) {
22
return area * 10;
23
}
24
}
25
public class SquareInheritance {
26
public static void Main(string[] args) {
27
square sq = new square();
28
int area;
29
sq.setSide(5);
30
area = sq.getArea();
31
32
// Print the area of the object.
33
Console.WriteLine("The area is: {0}", sq.getArea());
34
Console.WriteLine("The cost is: {0}", sq.getCost(area));
35
36
}
37
}
38
}
Cached Result