Constructor With Watch Class C# with Example



Constructor With Watch Class C# with Example

 		using System;

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

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

0 Comment's

Comment Form

Submit Comment