主题:抽象的困惑...
[em1]大家看一下这个程序...
using System;
using System.Collections.Generic;
using System.Text;
namespace 抽象方法和属性在派生类中实现
{
abstract class Base
{
protected double x;
protected double y;
public abstract double x
{
get;
set;
}
public abstract double y
{
get;
set;
}
public abstract void MyMethod();
}
class Derived : Base
{
public override double x
{
get
{
return x;
}
set
{
x = value;
}
}
public override double y
{
get
{
return y;
}
set
{
x = value;
}
}
public override void MyMethod()
{
Console.WriteLine("Method Mythod in Base has now been completed.");
}
}
class MainClass
{
public static void Main()
{
Derived myderived=new Derived();
Console.WriteLine("Please input the value of x;");
myderived.x=double.Parse(Console.ReadLine());
Console.WriteLine("Please input the value of y:");
myderived.y=double.Parse(Console.ReadLine());
Console.WriteLine("The current value of x and y are x={0},y={1}",myderived.x,myderived.y);
myderived.MyMethod();
}
}
}
这个程序完全是按一本书抄下来的,但结果却无法通过编译,出现这样的错误提示:
"类型'抽象方法和属性在派生类中实现.Base'已经包含"x(y)"的定义"..
我找了好久也找不好原因,各位好手帮一下忙了...[em1][em2]
using System;
using System.Collections.Generic;
using System.Text;
namespace 抽象方法和属性在派生类中实现
{
abstract class Base
{
protected double x;
protected double y;
public abstract double x
{
get;
set;
}
public abstract double y
{
get;
set;
}
public abstract void MyMethod();
}
class Derived : Base
{
public override double x
{
get
{
return x;
}
set
{
x = value;
}
}
public override double y
{
get
{
return y;
}
set
{
x = value;
}
}
public override void MyMethod()
{
Console.WriteLine("Method Mythod in Base has now been completed.");
}
}
class MainClass
{
public static void Main()
{
Derived myderived=new Derived();
Console.WriteLine("Please input the value of x;");
myderived.x=double.Parse(Console.ReadLine());
Console.WriteLine("Please input the value of y:");
myderived.y=double.Parse(Console.ReadLine());
Console.WriteLine("The current value of x and y are x={0},y={1}",myderived.x,myderived.y);
myderived.MyMethod();
}
}
}
这个程序完全是按一本书抄下来的,但结果却无法通过编译,出现这样的错误提示:
"类型'抽象方法和属性在派生类中实现.Base'已经包含"x(y)"的定义"..
我找了好久也找不好原因,各位好手帮一下忙了...[em1][em2]