本帖最后由 劇情侢媄終究媞 于 2014-5-29 19:06 编辑
父类中有一个重载的构造方法可以给父类的私有字段赋值.那么子类能否调用父类的构造方法对父类的私有字段赋值.
- namespace 继承2
- {
- class Person
- {
- private string name;
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- private int age;
- public int Age
- {
- get { return age; }
- set { age = value; }
- }
- private char gender;
- public char Gender
- {
- get { return gender; }
- set { gender = value; }
- }
- public Person()
- {
-
- }
- public Person(string name,int age,char gender)
- {
- this.name = name;
- this.age = age;
- this.gender = gender;
-
- }
- }
- class Student:Person
- {
- private int score;
- public int Score
- {
- get { return score; }
- set { score = value; }
- }
- public Student(string name,int age,char gender,int score):base(name,age,gender)
- {
- this.score = score;
-
- }
- }
- }
复制代码
这样是不是算是子类调用父类的构造方法.来给父类的私有字段赋值的
|
|