本帖最后由 乘鱼飞 于 2013-4-22 19:54 编辑
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Proj7_6
- {
- public class Cal
- {
- protected double x;
- protected double y;
- public double sum(double x, double y)
- {
- return x + y;
- }
- public double sub(double x, double y)
- {
- return Math.Abs(x - y);
-
- }
- }
- public class Cal2 : Cal
- {
- public double mix(double x, double y)
- {
- return x * y;
- }
- public double div(double x, double y)
- {
- return x / y;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- double i=(double )(Console.Read());
- double j =( double )(Console.Read());
- Cal p = new Cal();
- Console.WriteLine("父类的加法 {0}",p.sum(i ,j ));
- Console.WriteLine("父类的减法 {0}", p.sub(0.2, 1.2));
- Cal2 pp = new Cal2();
- Console.WriteLine("子类继承的加法 {0}", pp.sum(1.3, 1.4));
- Console.WriteLine("子类继承的减法 {0}", pp.sub(2.5, 1.2));
- Console.WriteLine("子类的乘法 {0}", pp.mix(1.2, 1.2));
- Console.WriteLine("子类的除法 {0}", pp. div(3.6, 1.2));
-
- }
- }
- }
复制代码 double i=(double )(Console.Read());
double j =( double )(Console.Read());
Cal p = new Cal();
Console.WriteLine("父类的加法 {0}",p.sum(i ,j ));
为什么当我输入 0 0 做加法运算时 p.sum(i ,j )输出的是80 |