C# simple and easy program Q1. Create an Employee class with the relevant attributes and methods in addition of thefollowing specifications: It contains a default constructor. It contains a parameterized constructor. It contains a copy constructor.Q2. Incorporate static attributes and static methods in the Employee class where required.
Question
C# simple and easy program Q1. Create an Employee class with the relevant attributes and methods in addition of thefollowing specifications: It contains a default constructor. It contains a parameterized constructor. It contains a copy constructor.Q2. Incorporate static attributes and static methods in the Employee class where required.
Solution
Sure, here is a simple example of an Employee class in C# that meets your requirements:
public class Employee
{
// Attributes
public string Name { get; set; }
public int Age { get; set; }
public static int EmployeeCount { get; private set; } // Static attribute
// Default constructor
public Employee()
{
EmployeeCount++;
}
// Parameterized constructor
public Employee(string name, int age)
{
Name = name;
Age = age;
EmployeeCount++;
}
// Copy constructor
public Employee(Employee employee)
{
Name = employee.Name;
Age = employee.Age;
EmployeeCount++;
}
// Static method
public static void ResetCount()
{
EmployeeCount = 0;
}
}
In this class, Name and Age are instance attributes, EmployeeCount is a static attribute that keeps track of the total number of Employee instances.
The class has a default constructor that increments the EmployeeCount each time a new instance is created, a parameterized constructor that also increments the EmployeeCount and sets the Name and Age attributes, and a copy constructor that copies the Name and Age from another Employee instance and increments the EmployeeCount.
The ResetCount static method resets the EmployeeCount to 0.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.