Default Parameterized Constructor C# with Example



Default Parameterized Constructor C# with Example

 		using System;

		namespace CSharpClass{
		class Watch
		{
			public byte hour{set; get;}	
			public byte minute{set; get;}

			public Watch(byte h = 12, byte m = 0)
			{
				hour = h;
				minute = m;
			}
			
			public void DisplayTime()
			{
				Console.WriteLine(hour + ":" + minute);
			}
		}
			
			class UsingDefaultParameterizedConstructor{
				static void Main(String[] arg){
					Watch hmt = new Watch();
					Console.Write("Time of the HMT Watch is: ");
					hmt.DisplayTime();
					
					Watch sonata = new Watch(10,12);
					Console.Write("Time of the Sonata Watch is: ");
					sonata.DisplayTime();
				}
			}
		}
 

0 Comment's

Comment Form

Submit Comment