An abstract class can be declared using the declare keyword BA. An inheriting class can override the implemented methods of an interface C?. A class can implement abstract methods from m
Trang 1ACCP I10 SEMESTER 2 PCS – PROGRAMMING IN C#
MODULAR QUIZ
FOR Session 04
1 Which of these statements about abstract classes and abstract methods are true?
A An abstract class can be declared using the declare keyword
B An abstract class cannot be instantiated using the new keyword
C An abstract class be created by declaring and defining methods
D An abstract method can be declared without an access modifier
2 Which of these statements about interfaces are false?
A An interface can contain abstract as well as implemented methods
B An inheriting class can override the implemented methods of an interface
C A class can implement abstract methods from multiple interfaces
D An interface can implement multiple interfaces but only a single abstract class
3 You are trying to inherit the abstract class Vehicle and implement its methods in the subclass Ferrari Which of the following codes will help you to achieve this?
A
class Vehicle{
public void Wheels(){
Console.WriteLine("Every Car has four wheels");
}
public abstract void Speed();
}
class Ferrari : Vehicle {
public void Speed(){
Console.WriteLine("The Speed
of Ferrari exceeds 200 mph");
C
class Vehicle{
public void Wheels(){
Console.WriteLine("Every Car has four wheels");
} public abstract void Speed();
} class Ferrari extends Vehicle {
public override void Speed(){
Console.WriteLine("The Speed
of Ferrari exceeds 200 mph");
Trang 2static void Main(){
Ferrari objCar = new Ferrari();
objCar.Speed();
}
}
} static void Main(){
Ferrari objCar = new Ferrari(); objCar.Speed();
} }
B
abstract class Vehicle{
public void Wheels(){
Console.WriteLine("Every Car has four wheels");
}
public abstract void Speed();
}
class Ferrari :: Vehicle {
public override void Speed(){
Console.WriteLine("The Speed
of Ferrari exceeds 200 mph");
}
static void Main(){
Ferrari objCar = new Ferrari();
objCar.Speed();
}
}
D
abstract class Vehicle{
public void Wheels(){
Console.WriteLine("Every Car has four wheels");
} public abstract void Speed();
} class Ferrari : Vehicle {
public override void Speed(){
Console.WriteLine("The Speed
of Ferrari exceeds 200 mph");
} static void Main(){
Ferrari objCar = new Ferrari(); objCar.Speed();
} }
4 Which of these statements about the property accessors and the types of properties are true?
A The read-only property can be defined using the set accessor
B The write-only property can be defined using the get accessor
C The get accessor can be executed by referring to the name of the property
D The set accessor can be executed when the property is assigned a new value
5 Which of these statements about indexers are true?
A Indexers cannot be overloaded
B Indexers can be declared as static
Trang 3C Indexers can be overridden
D Indexers may or may not contain parameters
6 A property can be declared inside a class, struct, Interface.
A True
B False
7 Which of the following statements is correct about properties used in C#.NET?
A A property can simultaneously be read only or write only
B A property can be either read only or write only
C A write only property will have only get accessor
D A write only property will always return a value
8 A Student class has a property called rollNo and stu is a reference to a Student object and we want the statement stu.RollNo = 28 to fail Which of the following options will ensure this functionality?
A Declare rollNo property with both get and set accessors
B Declare rollNo property with only set accessor
C Declare rollNo property with get, set and normal accessors
D Declare rollNo property with only get accessor
E None of the above
9 If a class Student has an indexer, then which of the following is the correct way to declare this indexer to make the C#.NET code snippet given below work successfully?
Student s = new Student();
s[1, 2] = 35;
A class Student
{
int[ ] a = new int[5, 5];
public property WriteOnly int this[int i, int j]
{
C class Student {
int[ , ] a = new int[5, 5];
public int this[int i, int j]
{
Trang 4set
{
a[i, j] = value;
}
}
}
set { a[i, j] = value;
} } }
B class Student
{
int[ , ] a = new int[5, 5];
public int property WriteOnly
{
set
{
a[i, j] = value;
}
}
}
D class Student {
int[ , ] a = new int[5, 5];
int i, j;
public int this {
set { a[i, j] = value;
} } }
10 If Sample class has a Length property with set accessor then which of the following statements will work correctly?
A
Sample m = new Sample();
int l;
l = m.Length;
C Sample.Length = 20;
B
Sample m = new Sample();
m.Length = m.Length + 20;
D Console.WriteLine (Sample.Length);
E Sample m = new Sample();
m.Length = 10;
Trang 5Answers