Challenge - 5 Problems
Abstract Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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(); } }
Attempts:
2 left
💡 Hint
Remember that abstract classes cannot be instantiated directly, but you can create instances of derived classes.
✗ Incorrect
The variable 'a' is of type Animal but holds a Dog instance. The Dog class overrides the abstract Speak method, so calling a.Speak() prints 'Woof'.
🧠 Conceptual
intermediate1:30remaining
Abstract method characteristics
Which statement about abstract methods in C# is correct?
Attempts:
2 left
💡 Hint
Think about where abstract methods are allowed and their purpose.
✗ Incorrect
Abstract methods cannot have a body and must be declared inside abstract classes. They cannot be static or private because they require overriding in derived classes.
🔧 Debug
advanced2: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()); } }
Attempts:
2 left
💡 Hint
Check if all abstract methods are implemented in derived classes.
✗ Incorrect
The Circle class inherits from Shape but does not provide an implementation for the abstract method Area(), causing a compilation error.
📝 Syntax
advanced2: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 }
Attempts:
2 left
💡 Hint
Remember the order and keywords required for overriding methods.
✗ Incorrect
The correct syntax uses 'public override' followed by the method signature and body. Option D misses 'override', C has wrong keyword order, and A wrongly declares the method abstract with a body.
🚀 Application
expert3: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 }
Attempts:
2 left
💡 Hint
Count all abstract methods inherited from base classes that must be implemented.
✗ Incorrect
SmartPhone inherits from Phone which inherits from Device. Device has 2 abstract methods (PowerOn, PowerOff), Phone adds 1 (Call). SmartPhone must implement all 3.