Monday, February 28, 2011

MCQ: OOP's more ques

Analyze the following block of code and select the appropriate output:
for(int i=1;i < 5;i++)
{
 if(i % 2= =0)
  Console.WriteLine(“Hello World: ”+i);
}

A. Hello World 2
   Hello World 4
B. Hello World 1
   Hello World 2
   Hello World 3
   Hello World 4
C. Hello World: 1
   Hello World: 2
   Hello World: 3
   Hello World: 4
D. Hello World: 2
   Hello World: 4
ANSWER : D

class A
{
 public A(int i){}
}
class B:A
{
 static void Main(string[] args){Console.WriteLine("Hello");}
}
What is the result of the above program?
A. Hello
B. No Result
C. Error
D. Can't Say
ANSWER: C

What is the output of the following program segment?
double bonus = 500.0;
double sales = 200000.0;
if (sales >= 300000.0)
bonus += 250.0;
Console.WriteLine("Bonus: " + bonus.ToString());
Console.WriteLine("The End");
A. Bonus: 50.0
   The End
B. Bonus: 500.0
   The End
C. Bonus: 750.0
   The End
D. No output
ANSWER: B

What is the output of the following program segment?
double bonus = 500.0;
double sales = 200000.0;
if (sales >= 300000.0)
Console.WriteLine("Bonus: " + bonus.ToString());
bonus += 250.0;
A. Bonus: 50.0
B. Bonus: 500.0
C. Bonus: 750.0
D. No output
ANSWER: B

What is the output of the following program segment?
int n1 = 100;
int n2 = 200;
int n3 = n1 / n2;
if (n3 > 0)
{
n2 = n1;
n1 = n2;
}
else
{
n1 = n2;
n2 = n1;
}
Console.WriteLine(n1.ToString() + " " + n2.ToString());
A. 100 200
B. 200 100
C. 200 200
D. 100 100
ANSWER: C

What is the output of the following program segment?
int num = 100; char qwerty = 'B';
switch (qwerty)
{
 case 'A':
  num++;  break;
 case 'B':
  num += 2;  break;
 case 'C':
  num += 3;  break;
 case 'D':
  num += 4;  break;
}
Console.WriteLine("num = " + num.ToString());
A. 100
B. 102
C. 109
D. Error message

What is the last output by the following program segment?
int x, y;
x = 1;
while (x < 3)
{
y = 1;
x++;
while (y < 3)
{
y++;
Console.WriteLine((x + y).ToString());
}
}
A. 4
B. 5
C. 6
D. 7
ANSWER : C


How many ampersands (&) are displayed by the program segment below?
int n, p, q;
n = 5;
p = 1;
do
{
q = p;
while (q < n)
{
q += 2;
Console.WriteLine("&");
}
p += 2;
}
while ( p < n);
A. 1
B. 2
C. 3
D. 5
ANSWER : C

What value will be returned by the call m14(5,6)?
public static int m14 (int a, int b)
{
if (a == 0)
return 0;
else
return b + m14(a-1,b);
}
A. 1
B. 11
C. 30
D. 120
ANSWER : C


What value will be returned by the call m13(5) ?
public static int m13 (int n)
{
if (n == 1)
return 1;
else
return n * m13(n-1);
}
A. 5
B. 20
C. 24
D. 120
ANSWER : D


What value will be returned by the call m11(1) ?
public static int m11(int n)
{
if (n == 5)
return 0;
else
return n + m11(n+1);
}
A. 1
B. 10
C. 50
D. 75
ANSWER : B


What value will be returned by the call m10(5) ?
public static int m10 (int n)
{
if (n == 1)
return 25;
else
return n + m10(n-1);
}
A. 5
B. 39
C. 125
D. 195
ANSWER : B


What value will be returned by the call m09(5) ?
public static int m09 (int n)
{
if (n == 1)
return 25;
else
return m09(n-1);
}
A. 1
B. 5
C. 25
D. 125
ANSWER : C


Consider the count method below.
Public static void count(int a, int b)
{
if (a <= b)
{
count(a+1, b);
System.Console.Write(a + " ");
}
}
What will be displayed by the method call count(10,20)?
A. 10 11 12 13 14 15 16 17 18 19 20
B. 11 12 13 14 15 16 17 18 19 20
C. 20 19 18 17 16 15 14 13 12 11 10
D. 20 19 18 17 16 15 14 13 12 11
ANSWER : C


Consider the count method below.
Public static void count(int a, int b)
{
if (a <= b)
{
System.Console.Write(a + " ");
Count(a+1, b);
}
}
What will be displayed by the method call count(10,20)?
A. 10 11 12 13 14 15 16 17 18 19 20
B. 11 12 13 14 15 16 17 18 19 20
C. 20 19 18 17 16 15 14 13 12 11 10
D. 20 19 18 17 16 15 14 13 12 11
ANSWER : A


What makes OOP so popular ?
i.  Data abstraction
ii  easily reusable
iii.easily modifiable
iv.none of the above 
A. i only
B. ii & iii only
C. i , ii & iii only
D. iv only
ANSWER : C

No comments:

Post a Comment