using System;
class Program
{
class Person {
protected int Age {get; set;}
protected string Name {get; set;}
}
class Student : Person {
public Student(string nm) {
Name = nm;
}
public void Speak() {
Console.Write("Name: "+Name);
}
}
static void Main(string[] args)
{
Student s = new Student("David");
s.Speak();
}
}
--->Output: Name:David
In the above code we have 'get' and 'set' methods used..
Now...
using System; class Program { class Person {
protected string Name;
}
class Student : Person {
public Student(string nm) {
Name = nm;
}
public void Speak() {
Console.Write("Name: "+Name);
}
}
static void Main(string[] args)
{
Student s = new Student("David");
s.Speak();
}
}
--->Output: Name:David
Here i have removed the 'get' and 'set' methods but the output was same. Then what is the use of those methods?