Answer to Question #318113 in C# for Jessayy

Question #318113

Create a person class and instantiate an object student based on this Class. The class can set an age, say hello, display her age on the screen and start the explanation.





Example of the output




My age is 21 years old




I'm studying




Hello!




I'm explaining

1
Expert's answer
2022-03-25T12:10:34-0400
using System;
using System.Collections.Generic;




namespace App
{




    class Person
    {
        
        protected int age;








        public Person()
        {
            
        }








        public virtual void Greet() // Method for greeting
        {
            Console.WriteLine("Hello!\nI'm explaining");
        }
















        public void SetAge(int n) // Method for setting age
        {
            this.age = n;
        }
    }




    class Student : Person
    {
        public Student()
        {








        }








        public void DisplayAge()
        {
            Console.WriteLine("My age is " + age + " years old.");
        }








        public void Studying()
        {
            Console.WriteLine("I'm studying.");
        }








    }






    class Program
    {




        static void Main(string[] args)
        {




            Student student = new Student();
            student.SetAge(21);
            student.DisplayAge();
            student.Studying();
            student.Greet();








        












            Console.ReadLine();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS