Box Class Static Data Member Outside Class C# with Example



Box Class Static Data Member Outside Class C# with Example

 	using System;

	namespace CSharpClass{
		class Box{
			static double count;
			double width;
			double height;
			double length;
			
			public void SetSize(double h, double l, double w){
				height = h;
				width = w;
				length = l;
				count++;
			}
		}
		
		class UsingBoxClass {
			static void Main(String[] arg){
				Console.WriteLine("CPU Cabinet Information");
				Box cpuCabinet = new Box();
				cpuCabinet.SetSize(10, 20, 30);
				Console.WriteLine("Total Object Created: " + Box.count);
				
				Console.WriteLine("\nHard Disk Information");
				Box hardDisk = new Box();
				hardDisk.SetSize(5, 8, 10);
				Console.WriteLine("Total Object Created: " + Box.count);
				
				Console.WriteLine("\nMonitor Information");
				Box monitor = new Box();
				monitor.SetSize(10, 3, 20);
				Console.WriteLine("Total Object Created: " + Box.count);
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment