Challenge - 5 Problems
Class Syntax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple class instance property
What is the output of this C# code?
C Sharp (C#)
class Person { public string Name = "Alice"; } var p = new Person(); Console.WriteLine(p.Name);
Attempts:
2 left
💡 Hint
Look at the value assigned to the Name field inside the Person class.
✗ Incorrect
The class Person has a public field Name initialized to "Alice". Creating an instance and printing p.Name outputs "Alice".
📝 Syntax
intermediate2:00remaining
Identify the syntax error in class declaration
Which option contains a syntax error in the class declaration?
Attempts:
2 left
💡 Hint
Check if all braces are properly closed.
✗ Incorrect
Option A is missing the closing brace for the class Plane, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does this class instantiation cause an error?
What error will this code produce and why?
C Sharp (C#)
class Animal { private Animal() { } } var a = new Animal();
Attempts:
2 left
💡 Hint
Check the accessibility of the constructor.
✗ Incorrect
The constructor is private, so it cannot be called outside the class. Trying to create an instance causes a compile-time accessibility error.
🧠 Conceptual
advanced2:00remaining
Effect of 'sealed' keyword on class inheritance
What happens if you try to inherit from a sealed class in C#?
C Sharp (C#)
sealed class Vehicle { } class Car : Vehicle { }
Attempts:
2 left
💡 Hint
The sealed keyword prevents inheritance.
✗ Incorrect
A sealed class cannot be used as a base class. Attempting to inherit from it causes a compile-time error.
🚀 Application
expert2:00remaining
Number of members in a class with properties and methods
How many members does this class have?
C Sharp (C#)
public class Calculator { public int Add(int a, int b) => a + b; public int Subtract(int a, int b) => a - b; public int Result { get; private set; } private void Reset() { Result = 0; } }
Attempts:
2 left
💡 Hint
Count all methods and properties declared inside the class.
✗ Incorrect
The class has 2 public methods (Add, Subtract), 1 property (Result), and 1 private method (Reset), totaling 4 members.