Is it known as constructor overloading ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
//we can also print it from constructor using System; namespace ConstructorOverloading { class GameScore { string user; int age; int salary; public GameScore() //it is default constructor { user = "Steven"; age = 28; Console.WriteLine("Previous user: "+user+" and he was "+age+" year old"); } public GameScore(string name,int age) { user = name; this.age = age; Console.WriteLine("Current user {0} and he is {1} years old",user,this.age); } public GameScore(int age, int salary) { this.age = age; this.salary = salary; Console.WriteLine("From the third constructor Age="+age+" Salary:"+salary); } public void Display(int no) { Console.WriteLine("Output from "+no+" no. Constructor"); } } class Program { static void Main(string[] args) { GameScore g1=new GameScore(); GameScore g2=new GameScore("Zaki",25); GameScore g3=new GameScore(90,99); g3.Display(3); Console.ReadKey(); } } } |