Font size
WorksheetsC# Quiz #1
Total questions: 25
Worksheet time: 14mins
Which of the following statements about inheritance in C# is correct?
A. A class in C# can inherit from multiple base classes.
B. A class in C# can only inherit from interfaces, not other classes.
C. A class in C# can inherit from one base class and implement multiple interfaces.
Which of the following statements about inheritance in C# is true?
A class in C# can inherit from multiple base classes.
Inheritance in C# is only possible with abstract classes.
A derived class inherits all members of the base class, including private members.
A class can inherit from another class using the : symbol.
Which access modifier allows a class member to be accessible in derived classes but not outside the class?
public
private
protected
internal
Which of the following can be inherited in C#?
Constructors
Private fields
Static methods
Public and protected methods
Can a class inherit from multiple classes in C#?
Yes, using multiple colons
No, C# does not support multiple inheritance of classes
Yes, using the multiple keyword
Only in .NET 7 or later
Which keyword is used to prevent a class from being inherited?
static
abstract
sealed
readonly
Given the classes below, what type of inheritance is shown?
class Vehicle { }
class Car : Vehicle { }
class Truck : Vehicle { }
Single Inheritance
e
Multilevel Inheritance
Hierarchical Inheritance
Multiple Inheritance
What symbol is used to declare inheritance in C#?
(a)
In C#, inheritance allows a class to:
Prevent objects from being instantiated
Reuse properties and behaviors from another class
Access system libraries automatically
Contain multiple unrelated methods
A derived class is one that:
Provides services to a base class
Inherits from another class
Cannot have constructors
Has no properties
Which of the following is not inherited from a base class?
Private Methods
Public methods
Protected methods
Public properties
The virtual keyword in a base class method indicates that:
The method can be overridden by a derived class
The method is static
The method cannot be accessed outside the class
The method is asynchronous
If a derived class has its own version of a base class method, this is known as:
Overriding
Shadowing
Hiding
Encapsulation
The act of creating a new instance of a class is called (a) .
What is the keyword used to import namespaces and libraries in C#?
using
namespace
class
public
Which keyword is used to define a class in C#?
using
namespace
class
public
What is the keyword used to make class members accessible from outside?
public
private
static
void
Which keyword is used to define a method that returns nothing in C#?
void
int
string
bool
Which keyword is used to define a constant in C#?
const
static
var
public
is a name given to a storage area that is used to store values of various data types
Visual Studio 2010 (VS)
Namespace declaration
variable
Arithmetic Operators
Example of Arithmetic Operators
&&
==
+
Write code that states: if coins equal 100 or 150 give an extra life. (Hint: need to know symbol for "or" and "equals".
if (coins == 100 || coins == 150) { lives += 1; }
if (coins = 100 % coins = 150) { lives += 1; }
if (coins AND 100 OR coins AND 150) { lives += 1; }
if (coins += 100 | coins += 150) { lives += 1; }
The this keyword inside a class refers to:
The base class
The current instance of the class
A static member
The parent namespace
To define an indexer, you use:
indexer keyword
this keyword with [ ]
getIndex() method
ArrayList inheritance
