#5 Pract C#
#5 Pract C#
using System;
namespace MyApplication {
class Program {
Console.WriteLine("{0}+{1}", a, B);
• a. 20
• b. 30
• c. 10+20
• d. 10+10
Answer: c. 10+20
Question 2: Which modifier is used while redefining an abstract method by a derived class in C#?
• a. Overloads
• b. New
• c. Override
• d. Virtual
Answer: c. Override
• a. :
• b. :
• c. ,
• d. .
Answer: c. ,
Question 4: Which is the right way to define an array?
• a. Every derived class does not define its own version of the virtual method.
• c. If a derived class does not define its own version of the virtual method, then the one present in
the base class gets used.
Answer: c. If a derived class does not define its own version of the virtual method, then the one present in
the base class gets used.
• a. Yes
• b. No
Answer: b. No
• d. Prevents inheritance
using System;
class Program {
int i = 100;
do (Console.Write(i + "");++i);
• a. Error
• c. 101
• d. 100
Answer: a. Error
Question 10: Which symbols are used to mark the beginning and end of a code block?
• a. Square brackets []
• b. Curly braces {}
• c. Round brackets ()
• d. Double-quotes ""
• a. { }
• b. 0
• c. Begin End
• d. []
Answer: a. { }
using System;
namespace MyApplication {
• a. 20, 20
• b. 10, 10
• c. 20, 10
Answer: c. 20, 10
• ○ a. Yes
• ○ b. No
Answer: b. No
Question 15: What does the 'abstract' keyword mean when applied to a class in C#?
Answer: b. The class cannot be instantiated and may contain abstract methods
Question 16: The protected access modifier defines a member that can be accessible within ___.
Question 17: Which of the following keywords enables modifying the data and behavior of a base class
by replacing its member with a new derived member?
• a. overloads
• b. overrides
• c. new
• d. base
Answer: c. new
Question 18: What will be the output of the following C# code?
using System;
class Program {
int i = 2;
int j = 10 / 4;
if (i == j) {
Console.WriteLine("True");
} else {
Console.WriteLine("False");
• a. True
• b. False
Answer: b. False
• a. // and //
• b. \and //
• d. /* and */
Answer: d. /* and */
Question 20: Which of the following is/are not types of arrays in C#?
• a. Single-dimensional
• b. Multidimensional
• c. Jagged arrays
• d. jazzed arrays
• d. There is no difference
Question 22: Which keyword is used to prevent a class from being inherited?
• a. final
• b. static
• c. sealed
• d. private
Answer: c. sealed
• a. Double
• b. long
• c. decimal
• d. ufloat
Answer: a. Double
Question 25: Which array property is used to get the total number of elements in C#?
• a. Len
• b. Length
• c. Elements
• d. MaxLen
Answer: b. Length
Question 26: Which keyword is used to specify that a method can be overridden in a derived class in C#?
• a. virtual
• b. override
• c. new
• d. base
Answer: a. virtual
• d. Error
Question 29: Which C# concept has the capability of an object to take a number of different forms and
hence display behavior accordingly?
• a. Polymorphism
• b. Encapsulation
• c. Abstraction
Answer: a. Polymorphism
Question 31: Which of the following String methods is used to compare two strings with each other?
• a. CompareTo()
• b. ConCat()
• c. Compare()
• d. Copy()
Answer: a. CompareTo()
• a. >
• b. !=
• c. ==
• d. <>
Answer: d. <>
Question 33: When a class serves as a base class for many derived classes, the situation is called______.
• a. Polymorphism
• b. hierarchical inheritance
• c. hybrid inheritance
• d. multipath inheritance
Question 35: Choose the correct output for the following piece of code:
Console.WriteLine(value);
• a. 1
• b. -1
• c. 0
• d. Error
Answer: a. 1
Question 36: Type of Conversion in which the compiler is unable to convert the data type implicitly is
• a. ushort to long
• b. int to uint
• c. All is correct
• d. byte to decimal
Question 37: What does the 'virtual' keyword indicate in a method declaration in C#?
Question 39: Which of the following is NOT a valid C# control flow statement?
• a. if-else
• b. switch
• c. for
• d. while-else
Answer: d. while-else
Question 40: What is the default access modifier for a class member in C#?
• a. public
• b. private
• c. protected
• d. internal
Answer: b. private
Question 41: Which data type is used to store text value in C#?
• a. text
• b. txt
• c. string
• d. str
Answer: c. string
Question 42: To declare an array, define the variable type with ___.
• a. Square brackets []
• b. Curly brackets {}
• c. Round brackets ()
• a. Class
• b. Object
• c. Method
• d. Structure
Answer: a. Class
a) True
b) False
Answer: a.True
Question 45: The protected access modifier defines a member that can be accessible within
a) 4 Bytes
b) 5 Bytes
c) 8 Bytes
Answer: a. 4Bytes
Question 48: How many times can a constructor be called during lifetime of the object?
a) Only once.
Question 49: Which of the following String method is used to compare two strings with each other?
a) Compare To()
b) ConCat()
c) Compare()
d) Copy()
a) break
b) continue
c) Both A and B
Answer: a. break
Question 51: Which type of class does not have its own objects but acts as a base class for its subclass
in C#?
a) Abstract Class
b) Static Class
C) Sealed Class
d) Protected Class