Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApplication27
- {
- class Person
- {
- public string name;
- public int age;
- public Person():this( "неизвестно")
- {
- }
- public Person(string name):this(name,18)
- {
- }
- public Person(string name, int age)
- {
- this.name=name;
- this.age=age;
- }
- public void GetInfo()
- {
- Console.WriteLine("Имя: {0} Возраст: {1}", name, age);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Person tom = new Person();//вызов первого конструктора
- Person bob = new Person("bob");//вызов второго конструктора
- Person sam = new Person("sam", 25);//вызов третьего конструктора
- tom.GetInfo();
- bob.GetInfo();
- sam.GetInfo();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement