Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Practicing Inheritance | OOP Principles
course content

Зміст курсу

C# Beyond Basics

Practicing InheritancePracticing Inheritance

Fill in the blanks to make sure the base constructors are properly called in the following code:

cs

index.cs

Use the public className(arg1, arg2..) : base(arg1, arg2, …) syntax in the derived classes to call the base constructors.

    using System;

    class Animal
    {
        string species;
    
        public Animal(string species)
        {
            this.species = species;
        }
    
        public void Eat()
        {
            Console.WriteLine("The animal is eating.");
        }
    }
    
    class Dog : Animal
    {
        string breed;
    
        public Dog(string species, string breed) : base(species)
        {
            this.breed = breed;
        }
    
        public void Bark()
        {
            Console.WriteLine("Woof! Woof!");
        }
    }
    
    class GermanShepherd : Dog
    {
        public GermanShepherd(string species, string breed) : base(species, breed)
        {
            Console.WriteLine("GermanShepherd Object Created");
        }
    
        public void PerformGuardDuty()
        {
            Console.WriteLine("The German Shepherd is performing guard duty.");
        }
    }
    
    
    class ConsoleApp
    {
        static void Main()
        {
            new GermanShepherd("Canis lupus familiaris", "German Shepherd");
        }
    }    
    

Все було зрозуміло?

Секція 5. Розділ 3
course content

Зміст курсу

C# Beyond Basics

Practicing InheritancePracticing Inheritance

Fill in the blanks to make sure the base constructors are properly called in the following code:

cs

index.cs

Use the public className(arg1, arg2..) : base(arg1, arg2, …) syntax in the derived classes to call the base constructors.

    using System;

    class Animal
    {
        string species;
    
        public Animal(string species)
        {
            this.species = species;
        }
    
        public void Eat()
        {
            Console.WriteLine("The animal is eating.");
        }
    }
    
    class Dog : Animal
    {
        string breed;
    
        public Dog(string species, string breed) : base(species)
        {
            this.breed = breed;
        }
    
        public void Bark()
        {
            Console.WriteLine("Woof! Woof!");
        }
    }
    
    class GermanShepherd : Dog
    {
        public GermanShepherd(string species, string breed) : base(species, breed)
        {
            Console.WriteLine("GermanShepherd Object Created");
        }
    
        public void PerformGuardDuty()
        {
            Console.WriteLine("The German Shepherd is performing guard duty.");
        }
    }
    
    
    class ConsoleApp
    {
        static void Main()
        {
            new GermanShepherd("Canis lupus familiaris", "German Shepherd");
        }
    }    
    

Все було зрозуміло?

Секція 5. Розділ 3
some-alt