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

When to use abstract vs concrete in C Sharp (C#) - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is an abstract class in C#?
An abstract class is a class that cannot be instantiated on its own and is meant to be a base class. It can contain abstract methods (without implementation) that derived classes must implement.
Click to reveal answer
beginner
What is a concrete class in C#?
A concrete class is a class that can be instantiated directly. It provides full implementations of its methods and can be used to create objects.
Click to reveal answer
intermediate
When should you use an abstract class instead of a concrete class?
Use an abstract class when you want to define a common base with shared code and require derived classes to implement specific methods. It helps enforce a contract and reuse code.
Click to reveal answer
beginner
Can you instantiate an abstract class directly?
No, you cannot create an instance of an abstract class directly. You must create an instance of a derived concrete class.
Click to reveal answer
intermediate
Give a real-life example of when to use an abstract class.
Imagine a base class 'Vehicle' that defines common features like 'StartEngine' but leaves the 'Drive' method abstract because cars and boats drive differently. Concrete classes like 'Car' and 'Boat' implement 'Drive'.
Click to reveal answer
Which statement about abstract classes in C# is true?
AYou cannot create an instance of an abstract class.
BAbstract classes must have no methods.
CAbstract classes can only have private methods.
DAbstract classes are the same as interfaces.
When should you use a concrete class?
AWhen you want to force derived classes to implement methods.
BWhen you want to create objects directly with full method implementations.
CWhen you want to prevent instantiation.
DWhen you want to define only method signatures.
What happens if a class inherits from an abstract class but does not implement its abstract methods?
AThe abstract methods are ignored.
BThe code compiles without errors.
CThe derived class becomes concrete automatically.
DThe derived class must also be declared abstract.
Which of these is NOT a reason to use an abstract class?
ATo share common code among related classes.
BTo enforce a contract for derived classes.
CTo create objects directly.
DTo define some methods without implementation.
If you want to define a method that must be implemented differently by each subclass, you should:
AMake the method abstract in an abstract class.
BImplement the method fully in a concrete class.
CMake the method private.
DUse a static method.
Explain the difference between abstract and concrete classes and when to use each.
Think about base classes and objects you can create.
You got /5 concepts.
    Describe a real-world scenario where an abstract class is useful.
    Consider something like vehicles or animals.
    You got /4 concepts.