Box Class Multiple Instance Static Data Member C# with Example



Box Class Multiple Instance Static Data Member C# with Example

 	using System;

	namespace CSharpClass{
		class Box{
			static double count;
			double width;
			double height;
			double length;

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

0 Comment's

Comment Form