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

Abstract classes and methods in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Abstract Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of abstract class method call
What is the output of this C# program?
C Sharp (C#)
using System;
abstract class Animal {
    public abstract void Speak();
}
class Dog : Animal {
    public override void Speak() {
        Console.WriteLine("Woof");
    }
}
class Program {
    static void Main() {
        Animal a = new Dog();
        a.Speak();
    }
}
AWoof
BAnimal speaks
CCompilation error: Cannot create instance of abstract class
DRuntime error: Method not implemented
Attempts:
2 left
💡 Hint
Remember that abstract classes cannot be instantiated directly, but you can create instances of derived classes.
🧠 Conceptual
intermediate
1:30remaining
Abstract method characteristics
Which statement about abstract methods in C# is correct?
AAbstract methods can have a body with implementation.
BAbstract methods can be static.
CAbstract methods must be declared in abstract classes.
DAbstract methods can be private.
Attempts:
2 left
💡 Hint
Think about where abstract methods are allowed and their purpose.
🔧 Debug
advanced
2:30remaining
Identify the compilation error
What is the cause of the compilation error in this code?
C Sharp (C#)
using System;
abstract class Shape {
    public abstract double Area();
}
class Circle : Shape {
    public double Radius;
}
class Program {
    static void Main() {
        Circle c = new Circle();
        c.Radius = 5;
        Console.WriteLine(c.Area());
    }
}
AArea method must be static
BCircle does not implement the abstract method Area()
CRadius field must be private
DCannot instantiate abstract class Shape
Attempts:
2 left
💡 Hint
Check if all abstract methods are implemented in derived classes.
📝 Syntax
advanced
2:00remaining
Correct syntax for abstract method override
Which option shows the correct way to override an abstract method in C#?
C Sharp (C#)
abstract class Vehicle {
    public abstract void Start();
}
class Car : Vehicle {
    // Choose the correct override syntax here
}
Apublic abstract override void Start() { Console.WriteLine("Car started"); }
Bpublic void Start() { Console.WriteLine("Car started"); }
Coverride public void Start() { Console.WriteLine("Car started"); }
Dpublic override void Start() { Console.WriteLine("Car started"); }
Attempts:
2 left
💡 Hint
Remember the order and keywords required for overriding methods.
🚀 Application
expert
3:00remaining
Number of methods to implement
Given the following code, how many methods must the class 'SmartPhone' implement to compile successfully?
C Sharp (C#)
abstract class Device {
    public abstract void PowerOn();
    public abstract void PowerOff();
}
abstract class Phone : Device {
    public abstract void Call(string number);
}
class SmartPhone : Phone {
    // Implementations here
}
A3
B2
C1
D4
Attempts:
2 left
💡 Hint
Count all abstract methods inherited from base classes that must be implemented.