面向对象继承练习

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace winformjicheng
{
class Program
{
static void Main(string[] args)
{
student stu =new student("张飞","001","男",80);
stu.studentsayscore();
program1 pro = new program1("王五","008","男",7);
pro.program1say();
}
}

// 基类(父类)
class person
{


private string name;

public string Name
{
get { return name; }
set { name = value; }
}
private string code;

public string Code
{
get { return code; }
set { code = value; }
}
private string sex;

public string Sex
{
get { return sex; }
set { sex = value; }
}
// 构造函数(字段初始化)
public person(string name, string code, string sex)
{

this.name = name;
this.code = code;
this.sex = sex;
}
}


//程序员类、、、、、、、、、子类 派生类、、、、、、、、、、、、、、、

 

class program1 : person // 继承person
{
//成员字段
private int year;
//封装字段(ctrl+r +e)
public int Year
{
get { return year; }
set { year = value; }
}
//显示调用基类属性
public program1(string name, string code, string sex, int year)
: base(name, code, sex)
{
this.year = year;

}
// 方法
public void program1say()
{
Console.WriteLine("我叫{0},学号是{1},我是{2}生,我工作{3}年了", this.Name, this.Code, this.Sex, this.year);
}


}
// 学生类、、、、、、、、、、、、子类派生类、、、、、、、、、、、、、、
class student : person
{
private decimal score;

public decimal Score
{
get { return score; }
set { score = value; }
}

public student(string name, string code, string sex, decimal score)
: base(name, code, sex)
{
this.score = score;

}

public void studentsayscore()
{
Console.WriteLine("我叫{0},学号是{1},我是{2}生,今年考了{3}分", this.Name, this.Code, this.Sex, this.score);

}


}

 


}

转载于:https://www.cnblogs.com/woniu-net/p/4656177.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值