using System;
using System.Collections.Generic;
using System.Text;
namespace HELLO
{
class 矩形
{
static void Main(string[] args)
{
Line line = new Line();//实例化
line.widthcalue = 8;//属性赋值
line.lengthvalue = 9;//属性赋值
double area = line.area1();
Console.WriteLine("长方形的面积是{0}", area);
line.setlength(4);
line.setwidth(5);
double area1 = line.area1();
Console.WriteLine("长方形的面积是{0}", area1);
Line1 line1 = new Line1();
line1.setlength(3);
line1.setwidth(2);
Console.WriteLine("长方形的面积是{0}", line1.area1()); ;
}
class Line
{
internal double length, width;//私有字段,外部访问不到
public void setlength(double a) { length = a; } //通过公有的方法赋值私有字段
public void setwidth(double b) { width = b; }//通过公有的方法赋值私有字段
public double widthcalue { set { width = value; } get { return width; } }//属性赋值私有字段
public double lengthvalue { set { length = value; } get { return length; } }//属性赋值私有字段
public double area1() { return length * width; }//根据字段值计算
}
class Line1 : Line //继承
{
public new void setlength(double a) { length = a * 2; } //重写普通公有的方法赋值私有字段
public new void setwidth(double b) { width = b * 2; }//重写普通公有的方法赋值私有字段
public new double area1() { return length * width * 2; }//重写返回值
}
}
}