/*
* 创建一个抽象类A,该类中包含一个求两个数之和抽象方法。创建一个子类B,在B中重写求和方法,且使用方法重载使得方法可以
* 分别计算整数、双精度和字符串。
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
abstract class A
{
public abstract int sum(int a, int b);
}
class B : A
{
public override int sum(int a, int b)
{
return a + b;
}
public double sum(double a, double b)
{
return a + b;
}
public string sum(string a, string b)
{
return a + b;
}
}
class Program
{
static void Main(string[] args)
{
int a, b;
double c, d;
string e, f;
B g=new B();
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("{0}+{1}={2}", a, b, g.sum(a, b));
c = Convert.ToDouble(Console.ReadLine());
d = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("{0}+{1}={2}", c, d, g.sum(c, d));
e = Console.ReadLine();
f = Console.ReadLine();
Console.WriteLine("{0}+{1}={2}", e, f, g.sum(e, f));
Console.ReadKey();
}
}
}
运行结果: