Can a class have 2 objects with the same name? If yes then while displaying, which particular object's roll, name and course details get printed?
class Program
{
static void Main(string[] args)
{
Student st=null;
Console.WriteLine("Enter Records");
for (int i = 0; i < 3; i++)
{
st = new Student();
Console.WriteLine("Enter roll");
st.roll = int.Parse(Console.ReadLine());
Console.WriteLine("Enter name");
st.name = Console.ReadLine();
Console.WriteLine("Enter course");
st.course = Console.ReadLine();
}
Console.WriteLine("Show Records");
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Roll "+st.roll.ToString());
Console.WriteLine("Name "+st.name);
Console.WriteLine("Course "+st.course);
}
Console.ReadKey();
}
}
class Student
{
public int roll;
public string name;
public string course;
}
Studentneeds multiple courses, or something different?