can somebody explain to me the line by line coding of this program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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. [email protected]

27th Jul 2017, 1:51 PM
Shaik Abdullah Shah Alam
Shaik Abdullah Shah Alam - avatar
1 Answer
+ 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.
27th Jul 2017, 3:13 PM
Cohen Creber
Cohen Creber - avatar