You are on page 1of 4

Assignment 1

Student Name: Aakanksha Kumari UID:21MCA3223

Branch: MCA Section/Group:21MCA/10A

Semester: 3rd Date of Performance:31-08-

2022 Subject Name: Web Application Development Subject Code:21CAP-704

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";
}

public void Display()


{
Console.WriteLine($"rollNumber is : {rollNumber}\nName is : {name}");
}
}
class Test
{
static void Main(string[] args)
{
Student s1 = new Student();
s1.Display();
}
}

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;

public Student(int r, string n)


{
rollNumber = r;
name = n;
}

public void Display()


{
Console.WriteLine($"rollNumber is : {rollNumber}\nName is : {name}");
}
}

class Test
{
static void Main(string[] args)
{
Student s1 = new Student(3223, "Aakanksha");
s1.Display();
}
}

Output:

You might also like