Professional Documents
Culture Documents
Worksheet 1 - Attempt Review
Worksheet 1 - Attempt Review
1: Attempt review
My courses
https://lms.cuchd.in/mod/quiz/review.php?attempt=1111516&cmid=1039146 1
3/3/23, 7:59 PM Worksheet 1.1: Attempt review
Question 1
Complete
Marked out of
Do any one
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.
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
using System;
class Program
{
private string name;
{
get { return name; }
{
get { return rollNo; }
obj.RollNo = 20bca1146;
}
}
In this program, we have a class called "Program" with private fields for name and roll number. We also have
properties for each field, which allow us to get and set the values of the fields outside of the class.
In the Main method, we create an object of the Program class and use the properties to set the name and roll
number. We then use the properties again to retrieve and print the values.
output:-
https://lms.cuchd.in/mod/quiz/review.php?attempt=1111516&cmid=1039146 2
3/3/23, 7:59 PM Worksheet 1.1: Attempt review
This is because the program creates an instance of the "Program" class and sets the "Name" and "RollNo" properties of that instance to "
Previous activity
Jump to...
Next activity
https://lms.cuchd.in/mod/quiz/review.php?attempt=1111516&cmid=1039146 3