using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
public class person
{
public String name;
public int age;
public person()
{
this.name = "未知";
this.age=0;
}
public person(String name, int age)
{
this.name = name;
this.age = age;
}
public void prin()
{
Console.WriteLine("name={0},age={1}",this.name,this.age);
}
}
class Program
{
static void Main(string[] args)
{
String na=Console.ReadLine();
int ag=Convert.ToInt32(Console.ReadLine());
person r= new person();
r.name = na;
r.age = ag;
r.prin();
}
}
}
声明类person,该类定义了两个数据成员,一个带参的构造方法,一个具有两个参数的构造方法,一个方法prin()
最新推荐文章于 2024-05-04 18:19:22 发布