Object-oriented-inheritance exercises

Source: Internet
Author: User

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 ("Zhang Fei", "001", "Male", 80);
Stu.studentsayscore ();
PROGRAM1 Pro = new Program1 ("Harry", "008", "male", 7);
Pro.program1say ();
}
}

Base class (Parent Class)
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;}
}
Constructors (field initialization)
Public person (string name, string code, string sex)
{

THIS.name = name;
This.code = code;
This.sex = sex;
}
}


The programmer class 、、、、、、、、、 subclass derived Classes 、、、、、、、、、、、、、、、

Class Program1:person//Inherit person
{
Member Fields
private int year;
Encapsulate Field (Ctrl+r +e)
public int Year
{
get {return year;}
set {year = value;}
}
Show Call base class properties
Public program1 (string name, string code, string sex, int year)
: Base (name, code, sex)
{
This.year = year;

}
Method
public void Program1say ()
{
Console.WriteLine ("My name is {0}, the study number is {1}, I am {2} born, I work {3} years", this. Name, this. Code, this. Sex, this.year);
}


}
Student class 、、、、、、、、、、、、 subclass derived class 、、、、、、、、、、、、、、
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 ("My name is {0}, the study number is {1}, I am {2} Born, this year I tested {3} minutes", this. Name, this. Code, this. Sex, This.score);

}


}


}

Object-oriented-inheritance exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.