Professional Documents
Culture Documents
Exe 1 (21MCA3223 - AAKANKSHA KUMARI - WAD)
Exe 1 (21MCA3223 - AAKANKSHA KUMARI - WAD)
Task to be done:
QUESTION 1: Suppose we have class program and it contains the fields like name and roll
no and these fields are private fields and we want to access that outside the
class. Write a program to access these fields.
Code:
using System;
class Student
{
private int rollNumber;
private string name;
public Student()
{
rollNumber = 3223;
name = "Aakanksha kumari";
}
Output:
Question 2:
Suppose we have class program and it contains the fields like name and roll no and these fields
are private fields and we want to assign values to that outside the class. Write a program to
assign values to these fields.
Code:
using System;
class Student
{
private int rollNumber;
private string name;
class Test
{
static void Main(string[] args)
{
Student s1 = new Student(3223, "Aakanksha");
s1.Display();
}
}
Output: