Answer to Question #329542 in C# for Babar302

Question #329542

Create two classes named Mammals and MarineAnimals. Create another class named BlueWhale 

which inherits both the above classes. Now, create a function in each of these classes which prints 

"I am mammal", "I am a marine animal" and "I belong to both the categories: Mammals as well as 

Marine Animals" respectively. Now, create an object for each of the above class and try calling

 function of Mammals by the object of Mammal

 function of BlueWhale by the object of BlueWhale

 function of each of its parent by the object of BlueWhale

 function of MarineAnimal by the object of MarineAnimal


1
Expert's answer
2022-04-16T12:56:51-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace C_SHARP
{
    class Program
    {




        class Mammals
        {
            public void Mammalsprint()
            {
                Console.WriteLine("I am mammal.");
            }


        }
        class MarineAnimals : Mammals
        {
            public void MarineAnimalsprint()
            {
                Console.WriteLine("I am a marine animal.");
            }
            
        }
        class BlueWhale : MarineAnimals
        {
            public void BlueWhaleprint()
            {
                Console.WriteLine("I belong to both the categories: Mammals as well as Marine Animals.");
            }
        }


        static void Main(string[] args)
        {


            Mammals m = new Mammals();
            MarineAnimals ma = new MarineAnimals();
            BlueWhale bw = new BlueWhale();


            m.Mammalsprint();
            ma.Mammalsprint();
            ma.MarineAnimalsprint();
            bw.Mammalsprint();
            bw.MarineAnimalsprint();
            bw.BlueWhaleprint();


            Console.ReadKey();
        }
    }
}

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