Chinaunix首页 | 论坛 | 博客
  • 博客访问: 533487
  • 博文数量: 156
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1183
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-22 11:42
文章分类

全部博文(156)

文章存档

2015年(67)

2014年(89)

分类: C#/.net

2014-12-10 08:03:14


点击(此处)折叠或打开

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;

  5. namespace @class
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             student no = new student();
  12.             student Yangyanjie = new student( "001", "杨艳杰", "女", 20);
  13.             Console.BackgroundColor = ConsoleColor.DarkGreen;
  14.             System.Console.WriteLine(Yangyanjie.Showstudent());
  15.             Console.ReadKey();
  16.         }
  17.     }
  18.     public class student
  19.     {
  20.         public String id;
  21.         public String name;
  22.         public String sex;
  23.         int age = 20;

  24.         public student()//与类同名的方法,为构建函数生成时自动调用,默认的构建函数,用于对象的初始化
  25.         {
  26.             id = "001";
  27.             name = "无";
  28.             sex = "女";
  29.             age = 20;
  30.         }

  31.        public student(String inid, String innanme, String insex, int inage)//多态
  32.         {
  33.             id = inid;
  34.             name = innanme;
  35.             sex = insex;
  36.             age = inage;
  37.         }

  38.         public String Showstudent()
  39.         {
  40.             return ("序号:"+id +" 名字:" + name + " 性别:"+sex +" 年龄:"+age );
  41.         }
  42.     
  43.     }
  44. }

            输出结果:
                    

阅读(1884) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~