0
0
C Sharp (C#)programming~10 mins

When to use abstract vs concrete in C Sharp (C#) - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an abstract class in C#.

C Sharp (C#)
public [1] class Animal {
    public abstract void Speak();
}
Drag options to blanks, or click blank then click option'
Astatic
Bconcrete
Csealed
Dabstract
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'concrete' instead of 'abstract' to declare an abstract class.
2fill in blank
medium

Complete the code to create a concrete class that inherits from an abstract class.

C Sharp (C#)
public class Dog : Animal {
    public override void [1]() {
        Console.WriteLine("Woof!");
    }
}
Drag options to blanks, or click blank then click option'
ASpeak
BRun
CJump
DBark
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist in the abstract class.
3fill in blank
hard

Fix the error in the code by choosing the correct keyword for the class.

C Sharp (C#)
public [1] class Vehicle {
    public void Start() {
        Console.WriteLine("Starting vehicle");
    }
}
Drag options to blanks, or click blank then click option'
Asealed
Bconcrete
Cabstract
Dstatic
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'abstract' when the class has no abstract members.
4fill in blank
hard

Fill both blanks to define an abstract method and a concrete method in an abstract class.

C Sharp (C#)
public abstract class Shape {
    public abstract double [1]();
    public double [2]() {
        return 0;
    }
}
Drag options to blanks, or click blank then click option'
AArea
BPerimeter
CDraw
DCalculate
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to make a concrete method abstract or vice versa.
5fill in blank
hard

Fill all three blanks to create a concrete class that implements abstract methods and adds a new method.

C Sharp (C#)
public class Circle : Shape {
    public override double [1]() {
        return 3.14 * radius * radius;
    }
    public override double [2]() {
        return 2 * 3.14 * radius;
    }
    public double [3]() {
        return radius;
    }
    private double radius;
    public Circle(double r) {
        radius = r;
    }
}
Drag options to blanks, or click blank then click option'
AArea
BPerimeter
CGetRadius
DCalculate
Attempts:
3 left
💡 Hint
Common Mistakes
Not overriding all abstract methods or using wrong method names.