QUIZ 

CHAPTER 3

Your Name:



3.1 A significant difference between a property and a field is

(a) capitalization
(b) parentheses
(c) accessibility modifiers
(d) how they are declared

3.2 If a is an object and p is a property and we assign a.p = x, x is represented in p by

(a) value
(b) x
(c) p.x
(d) p

3.3 A type can have several constructors provided that

(a) they all have different names
(b) they all have different parameter lists (signatures)
(c) at least one is the default constructor
(d) one constructor initializes all the locally declared fields


3.4 Which statement is true?

(a) A property must have the same name as a field in that type, but with a capital letter.
(b) A property must always be public.
(c) A property defines get and set behaviour.
(d) A property defines get or set behaviour or both.

3.5 Adding a double and an int value will always result in a

(a) double value
(b) int value
(c) int value if the double value did not have a fractional part
(d) long value, if the double value is more than 231

3.6 The correct expression for the hour of a new DateTime object is

(a) new DateTime(2003,9,25).Hour
(b) new DateTime(2003,9,25).Hour()
(c) new DateTime(2003,9,25).getHour()
(d) Hour(new DateTime(2003,9,25))

3.7 A loop to print the first 10 odd numbers would be

(a)

for (int i=1; i<=10; i+=2)
	Console.WriteLine(i); 

(b)
for (int i=1; i<19; i+=2)
	Console.WriteLine(i);

(c)
for (int i=0; i<10; i++)
	Console.WriteLine(i*2+1);

(d)
for (int i=0; i<=10; i++)
	Console.WriteLine(i*2+1);

3.8 To print an integer, a real number to 2 decimal places and a currency, all separated by four spaces, and in that order, we would use

Console.WriteLine(s,i,r,c):
where s is

(a)

"{0,4}{1,4:f2}{2,4:C}"

(b)
"{0}{1,f:4,2}    {2,c:4,2}"

(c)
"{0}    {1:f2}    {2:C}"

(d)
"{0}\t{1:f2}\t{2:C2}"

3.9 A significant difference between a typed method and a void method is that

(a) A void method cannot be called in an expression
(b) A typed method cannot be called without an expression or assignment
(c) A typed method can only have in parameters
(d) A void method must be public

3.10 If we have declared a method

void Update (x, out y)
which of the following is completely correct?

(a) Update(w, z)
(b) Update(w, out z);
(c) Update(in w, out z);
(d) Both (b) and (c)