定义一个student类,成员变量是name和age,定义一个无参的构造方法和一个两个参数的构造方法,在测试类中分别调用这两个构造方法产生对象,并输出两个对象的name和age的值
1条回答 默认 最新
- threenewbee 2020-04-15 12:18关注
问题解决的话,请点我回答下面的采纳
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Q1063732 { class student { public string name; public int age; public student(string n, int a) { name = n; age = a; } public student() : this("noname", 0) { } public override string ToString() { return string.Format("name={0},age={1}",name,age); } } class Program { static void Main(string[] args) { student s1 = new student(); Console.WriteLine(s1); student s2 = new student("a", 20); Console.WriteLine(s2); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 对于相关问题的求解与代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料
- ¥15 使用R语言marginaleffects包进行边际效应图绘制