C# language Write a program to create a class employee, it consist of ID, name, department and address. All employees belongs to “Computer Science” department and it can never be changed by any means. Employee ID is initialized only once when Employee object is created, any further attempt to change ID should be failed. Class must have a 3 parameterized constructor to set values and two methods: print(): to display all the data of a particular employee totalObjects(): to count and print total number of objects that has been created In Main(), create atleast two objects of employee class, display their records by calling print() function and also print the total number of objects that has been created. [this question is continued on next page] Sample Main Method: static void Main(string[] args) { Employee obj1 = new Employee(1, "Zubair", "Karachi"); obj1.print(); Employee obj2 = new Employee(2, "Nabeel", "Islamabad"); obj2.print(); Employee.totalObjects(); } Sample Output: ID : 1 Name : Zubair Department : Computer Science Address : Karachi ************************* ID : 2 Name : Nabeel Department : Computer Science Address : Islamabad ************************* Total number of objects : 2
C# language
Write a
- print(): to display all the data of a particular employee
- totalObjects(): to count and print total number of objects that has been created
In Main(), create atleast two objects of employee class, display their records by calling print() function and also print the total number of objects that has been created.
[this question is continued on next page]
Sample Main Method:
static void Main(string[] args)
{
Employee obj1 = new Employee(1, "Zubair", "Karachi");
obj1.print();
Employee obj2 = new Employee(2, "Nabeel", "Islamabad");
obj2.print();
Employee.totalObjects();
}
Sample Output:
ID : 1
Name : Zubair
Department : Computer Science
Address : Karachi
*************************
ID : 2
Name : Nabeel
Department : Computer Science
Address : Islamabad
*************************
Total number of objects : 2
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images