Quiz
C# 1
Dieses Quiz enthält Fragetypen, die sich im gewohnten Player öffnen.
Fragen in diesem Quiz (40)
1The [blank_start]switch[blank_end] statement selects for execution a statement list having an associated label
that corresponds to the value of an expression- Aswitch
2Write the following code snippet:
int n = 20;
int d = n 5;
What will be the value of d after this code snippet is executed?- A25
- B26
- C27
- D28
3The [blank_start]do-while[blank_end] loop tests the condition at the bottom of the loop instead of at the top.
- Ado-while
4 Write the following code snippet:
private static void WhileTest()
{
int i = 1;
while (i < 5)
{
Console.WriteLine(“The value of i = {0}”, i);
i;
}
}
How many times will the while loop be executed in this code snippet?- A0
- B1
- C4
- D5
5The only operator that takes three arguments is the [blank_start]?:[blank_end] operator
- A?:
6Write the following code snippet:
int number1 = 10;
int number2 = 20;
if (number2 > number1)
Console.WriteLine(“number1”);
Console.WriteLine(“number2”);
What output will be displayed after this code snippet is executed?- Anumber1
- Bnumber2
- Cnumber1
number2 - Dnumber2
number1
7The [blank_start]foreach[blank_end] loop is the most compact way to iterate through the items in a collection.
- Aforeach
8In a switch statement, if none of the case statements match the switch expression, then
control is transferred to which statement?- Abreak
- Bcontinue
- Cdefault
- Dreturn
9On a 32-bit computer, a variable of int data type takes [blank_start]four[blank_end] bytes of memory
- Afour
10You need to write code that closes a connection to a database, and you need to make
sure this code is always executed regardless of whether an exception is thrown. Where
should you write this code?- AWithin a try block
- BWithin a catch block
- CWithin a finally block
- DWithin the Main method
11To access the first element of an array, you use an index of [blank_start]0[blank_end]
- A0
12You need to store values ranging from 0 to 255. You also need to make sure that your
program minimizes memory use. Which data type should you use to store these values?- Abyte
- Bchar
- Cshort
- Dint
13[blank_start]Recursion[blank_end] is a programming technique that causes a method to call itself in order to compute a result.
- ARecursion
14If you don’t have a base case in your recursive algorithm, you create an infinite recursion.
An infinite recursion will cause your program to throw an exception. Which exception
will your program throw in such a case?- AOutOfMemoryException
- BStackOverflowException
- CDivideByZeroException
- DInvalidOperationException
15[blank_start]Constants[blank_end] are data fields or local variables whose value cannot be modified.
- AConstants
16You are learning how to develop repetitive algorithms in C#. You write the following
method:
private static void ForTest()
{
for(int i = 1; i < 5;)
{
Console.WriteLine(“The value of i = {0}”, i);
}
}
How many repetitions will the for loop in this code perform?- A0
- B4
- C5
- DInfinite repetitions
17When an algorithm involves a large number of conditions, a(n) [blank_start]decision table[blank_end] is a compact
and readable format for presenting the algorithm.- Adecision table
18Which of the following C# features should you use to organize code and create globally
unique types?- AAssembly
- BNamespace
- CClass
- DData type
19A(n) [blank_start]flowchart[blank_end] is a graphical representation of an algorithm.
- Aflowchart
20You write the following code snippet:
int[] numbers = {1, 2, 3, 4};
int val = numbers[1];
You also create a variable of the RectangleHandler type like this:
RectangleHandler handler;
What is the value of the variable val after this code snippet is executed?- A1
- B2
- C3
- D4
21You want to restrict the access for a method to the containing class or to a class that
is derived from the containing class. Which access modifier should you use for this
method?- Apublic
- Bprivate
- Cprotected
- Dinternal
22A(n) [blank_start]class[blank_end] is a blueprint of an object.
- Aclass
23In a class, you defined a method called Render. This method provides functionality to
render bitmap files on the screen. You would like the derived classes to supersede this
functionality to support the rendering of additional image formats. You also want the
Render method of the derived classes to be executed even if a derived class is cast as the
base class. Which keyword should you use with the definition of the Render method in
the base class?- Aabstract
- Bvirtual
- Cnew
- Doverrides
24A class that does not provide a complete implementation must be declared with the
keyword [blank_start]abstract[blank_end]- Aabstract
25You defined a class AdvMath that defines advanced mathematical functionality. You do
not want the functionality of this class to be inherited into derived classes. What
keyword should you use to define the AdvMath class?- Asealed
- Babstract
- Cprivate
- Dinternal
26Classes that want to support comparison must implement the IComparable interface and
then provide a body for the [blank_start]CompareTo[blank_end] method.- ACompareTo
27You need to provide query functionality to several of your classes. Each class’s algorithm
for the query will likely be different. Also, not all the classes have an “is-a” relationship
with each other. How should you support this functionality?- AAdd the query functionality to a base class with the public access modifier
- BHave all the classes inherit from an abstract base class and override the base-class
method to provide their own query functionality - CHave all the classes inherit from a base class that provides the query functionality
- DCreate a common interface that is implemented by all the classes
28You can use the [blank_start]is[blank_end] operator to check whether it is legal to cast one type to
another type.- Ais
29Which of the following class elements should you use to define the behavior of a class?
- AMethod
- BProperty
- CEvent
- DDelegate
30Three main features of an object-oriented programming language are [blank_start]encapsulation[blank_end],
[blank_start]inheritance[blank_end], and _ [blank_start]polymorphism[blank_end].- Aencapsulation
- Binheritance
- Cpolymorphism
31You are writing code for a class named Product. You need to make sure that the data members
of the class are initialized to their correct values as soon as you create an object of the
Product class. The initialization code should be always executed. What should you do?- ACreate a static method in the Product class to initialize data members
- BCreate a constructor in the Product class to initialize data members
- CCreate a static property in the Product class to initialize data members
- DCreate an event in the Product class to initialize data members
32You can use [blank_start]namespaces[blank_end] to group related classes in order to reduce name collisions.
- Anamespaces
33You are creating a new class named Square that is derived from the Polygon class. The
Polygon class has the following code:
class Polygon
{
public virtual void Draw()
{
// additional code . . .
}
}
The Draw method in the Square class should provide new functionality but also hide the
Polygon class implementation of the Draw method. Which code segment should you use
to accomplish this?- Aclass Square: Polygon
{
public override void Draw()
{
// additional code . . .
}
} - Bclass Square: Polygon
{
public new void Draw()
{
// additional code . . .
}
} - Cclass Square: Polygon
{
public virtual void Draw()
{
// additional code . . .
}
} - Dclass Square: Polygon
{
public static void Draw()
{
// additional code . . .
}
}
- Aclass Square: Polygon
34The [blank_start]this[blank_end] keyword refers to the current instance of a class.
- Athis
35You are creating a new class named Rectangle. You write the following code:
class Rectangle: IComparable
{
public double Length { get; set; }
public double Width { get; set; }
public double GetArea()
{
return Length * Width;
}
public int CompareTo(object obj)
{
// to be completed
}
}
You need to complete the definition of the CompareTo method to enable comparison of
the Rectangle objects. Which of the following codes should you write?- Apublic int CompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() − target.GetArea();
if (diff == 0)
return 0;
else if (diff > 0)
return 1;
else return −1;
} - Bpublic int CompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
double diff = this.GetArea() − target.GetArea();
if (diff == 0)
return 1;
else if (diff > 0)
return −1;
else return 0;
} - Cpublic int CompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
if (this == target)
return 0;
else if (this > target)
return 1;
else return −1;
} - Dpublic int CompareTo(object obj)
{
Rectangle target = (Rectangle)obj;
if (this == target)
return 1;
else if (this > target)
return −1;
else return 0;
}
- Apublic int CompareTo(object obj)
36A(n) [blank_start]delegate[blank_end] is a type that references a method
- Adelegate
37You are writing code for a new method named Process:
void Process(object o)
{
}
The code receives a parameter of type object. You need to cast this object into the type
Rectangle. At times, the value of o that is passed to the method might not be a valid
Rectangle value. You need to make sure that the code does not generate any System.
InvalidCastException errors while doing the conversions. Which of the following lines of
code should you use inside the Process method to accomplish this goal?- ARectangle r = (Rectangle) o;
- BRectangle r = o as Rectangle;
- CRectangle r = o is Rectangle;
- DRectangle r = (o != null) ? o as rectangle: (Rectangle) o;
38A(n) [blank_start]struct[blank_end] is a value type, whereas a(n) [blank_start]class[blank_end] is a reference type.
- Astruct
- Bclass
39You are writing code to handle events in your program. You define a delegate named
RectangleHandler like this:
public delegate void RectangleHandler(Rectangle rect);
You also create a variable of the RectangleHandler type as follows:
RectangleHandler handler;
Later in the program, you need to add a method named DisplayArea to the method
invocation list of the handler variable. The signature of the DisplayArea method matches
the signature of the RectangleHandler method. Any code that you write should not
affect any existing event-handling code. Given this restriction, which of the following
codes should you write?- Ahandler = new RectangleHandler(DisplayArea);
- Bhandler = DisplayArea;
- Chandler += DisplayArea;
- Dhandler −= DisplayArea;
40You can use the [blank_start]static[blank_end] keyword to declare a member that belongs to the class
itself rather than to a specific object.- Astatic
Informationen
- Beschreibung
- Information Technology Quiz am C# 1, erstellt von José Kappert am 19/06/2017.
- Autor
- José Kappert
- Sprache
- English
- Aufrufe
- 5
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz