Write program in C#.
WAP on Encapsulation to hide the type members with private access
and display employee details.
• Create a new project, select console application from the
template and name the project as
“EmployeeDetails.cs”.
• Here type members are nothing but properties.
• Create another class as Employee and write the properties for
EmpId, EmpName and Salary.
• Now, create an instance of the Employee class in the
“EmployeeDetails” class and assign the values for
EmpId,EmpName and Salary and print the values.
HELLO,
I AM ATTACHING THE CODE IN C#
PLEASE GO THROUGH IT ONCE AND IF STILL HAVE ANY DOUBT FEEL FREE TO ASK IN COMMENT
AND IF THIS HELPS YOU PLEASE UPVOTE THE ANSWER
using System;
namespace EmployeeDetails
{
class EmployeeDetails
{
static void Main(string[] args)
{
Employee emp = new Employee();
emp.EmpId = 1;
emp.EmpName = "ABC NAME";
emp.Salary = 5000;
Console.WriteLine("Employee Id :"+emp.EmpId);
Console.WriteLine("Employee Name :" + emp.EmpName);
Console.WriteLine("Employee Salary :" + emp.Salary);
}
}
class Employee
{
public int EmpId;
public string EmpName;
public decimal Salary;
}
}
Get Answers For Free
Most questions answered within 1 hours.