68 263
Assignments Done
99%
Successfully Done
In November 2018

Answer to Question #2550 in C# for ch azan

Question #2550
Define a console application with a class ‘Employee’ with variables as emp_id (int), name (String) and Grade (double).Define five different constructors for this class to initialize the variable values. Define Finalize method to display the Grade value. Define a for loop in Main for 4 iterations and inside for loop create Employee object. After the for loop call Garbage Collector.
Expert's answer
using System;

namespace Employee
{
class Employee
{
& // Member variables of the class
& private int emp_id;
& private string name;
& private double grade;

& // The constructors

& // The default constructor
& public Employee()
& {
// Some default values
emp_id = 1;
grade = 1;
name = "Some name";
& }

& // Three different constructors depending on the amount of parameters

& public Employee(int pEmpId)
& {
emp_id = pEmpId;
& }

& public Employee(int pEmpId, string pName)
: this(pEmpId)
& {
name = pName;
& }

& public Employee(int pEmpId, string pName, double pGrade)
: this(pEmpId, pName)
& {
grade = pGrade;
& }

& // Finalize method (destructor)
& ~Employee()
& {
Console.WriteLine("Finalizator: grade = {0}", grade);
& }
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions