0
can somebody explain to me the line by line coding of this 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(); //Outputs "Name: David" } please give step by step explanation. word by word explanation. i really appreciate it. please, don't skip the basics. shaikabdullahshahalam@gmail.com
1 Resposta
+ 2
Starting from main, an instance of the Student class is created, which passes through a string for its constructor. The Student class' constructor sets the protected property from its base class, Person.
We use this object we created to call the Speak() function from the Student class, which just prints out "Name: ", and the name property from the Person base class, which was set when we actually created the object, due to Student's constructor.