点击(此处)折叠或打开
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace @class
- {
- class Program
- {
- static void Main(string[] args)
- {
- student no = new student();
- student Yangyanjie = new student( "001", "杨艳杰", "女", 20);
- Console.BackgroundColor = ConsoleColor.DarkGreen;
- System.Console.WriteLine(Yangyanjie.Showstudent());
- Console.ReadKey();
- }
- }
- public class student
- {
- public String id;
- public String name;
- public String sex;
- int age = 20;
- public student()//与类同名的方法,为构建函数生成时自动调用,默认的构建函数,用于对象的初始化
- {
- id = "001";
- name = "无";
- sex = "女";
- age = 20;
- }
- public student(String inid, String innanme, String insex, int inage)//多态
- {
- id = inid;
- name = innanme;
- sex = insex;
- age = inage;
- }
- public String Showstudent()
- {
- return ("序号:"+id +" 名字:" + name + " 性别:"+sex +" 年龄:"+age );
- }
-
- }
- }
输出结果: