using System; using System.Collections.Generic; using System.Text;
namespace ConsoleApplication1 { class Class1 { private int length; private int weight; public int x; public int y; public int LENGTH { get { return length; } set {
length = value < 0 ? -value : value; } }
public int WEIGHT { get { return weight; } set {
weight = value < 0 ? -value : value; } }
public int area; public Class1(int l, int w) { length = l; weight = w; }
public void SetArea() { area = length * weight; } public int Area() { return area; } } }
using System; using System.Collections.Generic; using System.Text; using System.Collections;//arraylist派生于array类
namespace ConsoleApplication1 { class Program:Class1 { int jj; public Program(int w, int h) : base(w, h) {
}
public int Ax() { //在派生类中的方法规(仅)可以访问基类的public成员 return LENGTH; }
public void testbase() { jj = x * y;//在派生类方法中访问 } public int aj() { return jj; }
static void Main(string[] args) {
Program p1 = new Program(20,45); //派生类实例对象可以访问基类的成员方法(公共)及属性及字段 p1.SetArea(); Console.WriteLine(p1.Area()); Console.ReadKey(); }