从派生类访问基类的非私有成员

.Net技术 码拜 9年前 (2014-12-13) 1068次浏览 0个评论
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace 实力5_2
{
class Program
{
public static void Main()
{
Student student = new Student(“大雄”, 12, “一中”);
Console.WriteLine(student.Name);
Console.WriteLine(student.Age);
Console.WriteLine(student.School);
}
}
class Person
{
public string Name;
public int Age;
public Person(string name, int age)
{
Name = name;
Age = age;
Console.WriteLine(“{0},{1}”, Name, Age);
}
}
class Student:Person
{
public string School;
public Student(string name,int age,string school):base(name,age)
{
School=school;
Console.WriteLine(“{0},{1},{2}”,Name,Age,School);
}
}
}


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明从派生类访问基类的非私有成员
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!