Quiz ---C# Programming
1.
Select output for
following set of code :
2. static void Main(string[] args)
3. {
4. int const p = 0;
5. switch (3 * 5 / 6)
6. {
7. case p:
8. Console.WriteLine("A");
9. break;
10. case p * 1:
11. Console.WriteLine("B");
12. break;
13. case p - 2:
14. Console.WriteLine("C");
15. break;
16. default:
17. Console.WriteLine("D");
18. }
19. }
a) A
b) B
c) C
d) Compile time error
b) B
c) C
d) Compile time error
2. Choose exact solution for following code snippet :
1. static void Main(string[] args)
2. {
3. int a , b;
4. int c = 10;
5. int d = 12;
6. int e = 5;
7. int f = 6;
8. a = c * (d + e) / f + d;
9. Console.WriteLine(a);
10. b = c * ( d + e / f + d);
11. Console.WriteLine(b);
12. if (a < b)
13. {
14. Console.WriteLine(" parantheses changes values");
15. }
16. else if (a > b)
17. {
18. Counterintelligence("they have same value");
19. }
20. Console.ReadLine();
21. }
a) They have same value
b) Parentheses changes values
c) Since, both have equal values no conclusion
d) None of the mentioned
b) Parentheses changes values
c) Since, both have equal values no conclusion
d) None of the mentioned
3. Correct
statement about following C#.NET code is?
class baseclass
{
int a;
public baseclass(int a1)
{
a = a1;
console.writeline(" a ");
}
class derivedclass : baseclass
{
public derivedclass (int a1) : base(a1)
{
console.writeline(" b
");
}
}
class program
{
static void main(string[] args)
{
derivedclass d = new derivedclass(20);
}
}
}
a) Compile time error
b) Output : b a
c)
Output : a b
d) the program will work correctly if we
replace base(a1) with base.baseclass(a1)
4. Choose the correct differences which diferent
enum from C#.NET than enum in C language?
a) C is a stricly typed language also C#.NET is a strictly typed language
b) In C language variables of enum types can be used interchangeably with integers using type casts while enum variables cannot be used as a normal integers
c) C is not a strictly typed language while C#.NET is a strictly typed language
d) All of the mentioned
a) C is a stricly typed language also C#.NET is a strictly typed language
b) In C language variables of enum types can be used interchangeably with integers using type casts while enum variables cannot be used as a normal integers
c) C is not a strictly typed language while C#.NET is a strictly typed language
d) All of the mentioned
Answer: b, c
5. Select output for
following set of code :
1. static void Main(string[] args)
2. {
3. int i = 2, j = 3, k = 4;
4. switch (i + j - k)
5. {
6. case 0: case 2: case 4:
7. ++i;
8. k += j;
9. break;
10. case 1: case 3: case 5 :
11. --i;
12. k -= j;
13. break;
14. default:
15. i += j;
16. break;
17. }
18. Console.WriteLine(i + "\n" + j + "\n" + k);
19. Console.ReadLine();
20. }
a) 1 3 1
b) 2 3 4
c) 5 3 4
d) Compile time error.
b) 2 3 4
c) 5 3 4
d) Compile time error.
6. The correct way of
incrementing the operators are :
a) ++ a ++
b) b ++ 1
c) c += 1
d) d =+ 1
a) ++ a ++
b) b ++ 1
c) c += 1
d) d =+ 1
7. What
is the output of following set of code?
static void Main(string[] args)
{
int a = 5;
int s = 0, c = 0;
Mul (a, ref s, ref c);
Console.WriteLine(s + "t " +c);
Console.ReadLine();
}
static void Mul (int x, ref int ss, ref int
cc)
{
ss = x * x;
cc = x * x * x;
}
a) 125 25
b)
25 125
c) Compile time error
d) 0 0
8. . Correct statement about C#.NET code given below is?
1. struct book
2. {
3. private String name;
4. private int pages;
5. private Single price;
6. }
7. book b = new book();
a) New structure can
be inherited from struct book
b) When the program terminates, variable b will get garbage collected
c) The structure variable ‘b’ will be created on the stack
d) When the program terminates, variable b will get garbage collected
b) When the program terminates, variable b will get garbage collected
c) The structure variable ‘b’ will be created on the stack
d) When the program terminates, variable b will get garbage collected
Answer: c
9. Select the output for
following set of code :
1. static void Main(string[] args)
2. {
3. int i = 9 , j = 7;
4. switch (i - j + 3)
5. {
6. case 9: 7:
7. j += 6;
8. break;
9. case 5:
10. i -= 4;
11. break;
12. }
13. Console.WriteLine(i + "\n" + j);
14. Console.ReadLine();
15. }
a) 5 7
b) 9 13
c) Compile time error
d) 9 7
b) 9 13
c) Compile time error
d) 9 7
10. Select the output for
following set of code :
1. static void Main(string[] args)
2. {
3. int x;
4. for (x = 1; x <= 3; x++)
5. {
6. int j = 1;
7. do
8. {
9. j++;
10. }while (x % j == 2);
11. Console.WriteLine(x + " " + j);
12. }
13. Console.ReadLine();
14. }
a) 1 12 1 3 1
b) 1 12 13 1
c) 12 22 32
d) 11 21 3
b) 1 12 13 1
c) 12 22 32
d) 11 21 3
11. What is the output of the code
?
static void Main(string[] args)
{
m();
Console.ReadLine();
}
static void m()
{
Console.WriteLine("HI");
m();
}
a) HI HI HI
b) HI
c)
Stack overflow exception
d) Compile time error
12. Correct statement about the C#.NET code given below is?
1. class trial
2. {
3. int i;
4. float d;
5. }
6. struct sample
7. {
8. private int x;
9. private Single y;
10. private trial z;
11.}
12.sample s = new sample();
a)
trial object referred by z created on the stack
b) z is created on the heap
c) Both s and z will be created on the heap
d) s will be created on the stack
b) z is created on the heap
c) Both s and z will be created on the heap
d) s will be created on the stack
Answer: d
13.
Select the output
for following set of Code :
1. static void Main(string[] args)
2. {
3. int i;
4. Console.WriteLine("enter value of i:");
5. i = Convert.ToInt32(Console.ReadLine());
6. if ( i % 2 == 0)
7. goto even:
8. else
9. {
10. Console.WriteLine("number is odd:");
11. Console.ReadLine();
12. }
13. even:
14. Console.WriteLine("number is even:");
15. Console.ReadLine();
16. }
17. for i = 4.
a)
number is odd
b) number is even
c) Compile time error
d) None of the mentioned
b) number is even
c) Compile time error
d) None of the mentioned
- What will be the output of the following code:
class ABC
{
static ABC()
{
MessageBox.Show(“ABC”);
}
public static void Hello()
{
MessageBox.Show(“Hello”);
}
}
class MyProgram
{
static void Main(string[ ] args)
{
ABC.Hello();
}
}
(a) ABC Hello
(b) ABC
(c) Hello
(d) Error
15.Choose correct statement which support facts that why C#
doesnot allow creation of empty structures?
a) C#.NET supports creation of abstract user-defined data types using structures
b) By having empty structures,it would mean that the new data types has no data associated with which donot make any sense in C#.NET
c) Basic reason to create structures is inability to represent real life objects using standard data types offered by the language
d) All of the above mentioned
a) C#.NET supports creation of abstract user-defined data types using structures
b) By having empty structures,it would mean that the new data types has no data associated with which donot make any sense in C#.NET
c) Basic reason to create structures is inability to represent real life objects using standard data types offered by the language
d) All of the above mentioned
Answer: d
16. Select the output
for following set of code :
1. static void Main(string[] args)
2. {
3. int i, j;
4. for (i = 1; i <= 3; i++)
5. {
6. j = 1;
7. while (i % j == 2)
8. {
9. j++;
10. }
11. Console.WriteLine(i + " " + j);
12. }
13. Console.ReadLine();
14. }
a) 11 21 31
b) 1 12 13 1
c) 11 21 31
d) 1 1 2 1 3 1
b) 1 12 13 1
c) 11 21 31
d) 1 1 2 1 3 1
17. If we define a class without any members, What will
happen?
(a) Error will be generated
(b) It will be successfully
compiled
(c) System will crash
(d) None of the above
- Which of the following is the correct syntax for declaring methods?
(a) type methodname(parameter‐list)
{
method‐body;
}
(b) methodname
type(parameter‐list)
{
method‐body;
}
(c) Parameter‐list methodname(type)
{
method‐body;
}
(d) None of the above
19.Select the output for following set of code :
1. static void Main(string[] args)
2. {
3. int i = 10 , j = 0;
4. label:
5. i--;
6. if ( i > 0)
7. {
8. Console.WriteLine(i+ " ");
9. goto label;
10. }
11. Console.ReadLine();
12. }
a)
1 2 3 4 5 6 7 8 9 10
b) 10 9 8 7 6 5 4 3 2 1 0
c) 9 8 7 6 5 4 3 2 1
d) 10 9 8 7 6 5 4 3 2 1
b) 10 9 8 7 6 5 4 3 2 1 0
c) 9 8 7 6 5 4 3 2 1
d) 10 9 8 7 6 5 4 3 2 1
20. When we call a constructor method among different
given constructors. We match the suitable constructor by matching the name of
constructor first then the number and type of parameters to decide which
constructor to be overloaded.The process is also known as?
a) Method overriding
b) Inheritance
c) Polymorphism
d) Encapsulation
- Which of these
keywords is used to refer to member of base class from a sub class?
a) upper
b) base
c) this
d) None of the
mentioned
22. Choose correct statement about structures why they are
defined as value types but not reference typeS?
a) Since space required for structure variables is allocated on stack which is a form of memory that is automatically available when a variable to be used is in scope.
b) Structures generally used to represent user defined data types that consists of small amount of data in them hence using stack for deceleration of such variables is not problem.
c) All of the mentioned
d) None of the mentioned
a) Since space required for structure variables is allocated on stack which is a form of memory that is automatically available when a variable to be used is in scope.
b) Structures generally used to represent user defined data types that consists of small amount of data in them hence using stack for deceleration of such variables is not problem.
c) All of the mentioned
d) None of the mentioned
Answer: c
23. Select the output for
following set of code:
1. static void Main(string[] args)
2. {
3. float s = 0.1f;
4. while (s <= 0.5f)
5. {
6. ++s;
7. Console.WriteLine(s);
8. }
9. Console.ReadLine();
10. }
a) 0.1
b) 1.1
c) 0.1 0.2 0.3 0.4 0.5
d) No output
b) 1.1
c) 0.1 0.2 0.3 0.4 0.5
d) No output
24. Choose correct statement about structures in C#.NET?
a) Structures can be declared within a procedure
b) Structs can implement an interface but they cannot inherit from another struct
c) Struct members cannot be declared as protected
d) A structure can be empty
a) Structures can be declared within a procedure
b) Structs can implement an interface but they cannot inherit from another struct
c) Struct members cannot be declared as protected
d) A structure can be empty
Answer: b, c
25. The correct way to define a variable of type struct abc among following is?
1. struct abc
2. {
3. public string name;
4. protected internal int age;
5. private Single sal;
6. }
a) abc
e = new abc();
b) abc e;
c) abc e;
e = new abc;
d) abc e = new abc;
b) abc e;
c) abc e;
e = new abc;
d) abc e = new abc;
Answer: a, b
26. Select the output for
following set of Code:
1. static void Main(string[] args)
2. {
3. int i;
4. i = 0;
5. while (i++ < 5)
6. {
7. Console.WriteLine(i);
8. }
9. Console.WriteLine("\n");
10. i = 0;
11. while ( ++i < 5)
12. {
13. Console.WriteLine(i);
14. }
15. Console.ReadLine();
16. }
a) 1 2 3 4
1 2 3 4 5
b) 1 2 3
1 2 3 4
c) 1 2 3 4 5
1 2 3 4
d) 1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
b) 1 2 3
1 2 3 4
c) 1 2 3 4 5
1 2 3 4
d) 1 2 3 4 5
1 2 3 4 5
27. Select the output for
following set of code :
1. static void Main(string[] args)
2. {
3. int i = 0;
4. if (i == 0)
5. {
6. goto label;
7. }
8. label: Console.WriteLine("HI...");
9. Console.ReadLine();
10. }
a)
Hi…infinite times
b) Code runs printed nothing
c) Hi Hi
d) Hi…
b) Code runs printed nothing
c) Hi Hi
d) Hi…
28. When does structure variable get destroyed?
a) When no reference refers to it,it will get garbage collected
b) Depends on either it is created using new or without new operator
c) As variable goes out of the scope
d) Depends on either we free it’s memory using free() or delete()
a) When no reference refers to it,it will get garbage collected
b) Depends on either it is created using new or without new operator
c) As variable goes out of the scope
d) Depends on either we free it’s memory using free() or delete()
Answer: c
29. Select correct statements among the following?
a) A struct can contain properties
b) A struct can contain constructors
c) A struct can contain protected data members
d) A struct cannot contain constants
a) A struct can contain properties
b) A struct can contain constructors
c) A struct can contain protected data members
d) A struct cannot contain constants
Answer: a, b
30. Select the output for
following set of code :
1. static void Main(string[] args)
2. {
3. int i = 0, j = 0;
4. l1: while (i < 2)
5. {
6. i++;
7. while (j < 3)
8. {
9. Console.WriteLine("loop\n");
10. goto l1;
11. }
12. }
13. Console.ReadLine();
14. }
a) loop printed infinite times
b) loop
c) loop loop
d) Compile time error
b) loop
c) loop loop
d) Compile time error
No comments:
Post a Comment