How to override a class in C#? Example.

 class Student
    {
        public void Name()
        {
            Console.WriteLine("Kulshresth");
        }
    }
    class Student_Details:Student
    {
        public void Name()
        {
            Console.WriteLine("Kulshresth Kumar");
        }

        public void Name(string lastname)
        {
            Console.WriteLine("Kulshresth Kumar " + lastname);
        }
    }------------------------------

class Program
    {
        static void Main(string[] args)
        {
            Student_Details obj = new Student_Details();
            obj.Name();
            obj.Name("Nagar");
            Console.ReadLine();
        }
    }
Share:

No comments:

Post a Comment

Friday, 28 June 2019

How to override a class in C#? Example.

 class Student
    {
        public void Name()
        {
            Console.WriteLine("Kulshresth");
        }
    }
    class Student_Details:Student
    {
        public void Name()
        {
            Console.WriteLine("Kulshresth Kumar");
        }

        public void Name(string lastname)
        {
            Console.WriteLine("Kulshresth Kumar " + lastname);
        }
    }------------------------------

class Program
    {
        static void Main(string[] args)
        {
            Student_Details obj = new Student_Details();
            obj.Name();
            obj.Name("Nagar");
            Console.ReadLine();
        }
    }

No comments:

Post a Comment

Popular

Total Pageviews

Archive