C# Programming Trivia: Quiz!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Anitha
A
Anitha
Community Contributor
Quizzes Created: 2 | Total Attempts: 2,486
Questions: 9 | Attempts: 227

SettingsSettingsSettings
C# Programming Trivia: Quiz! - Quiz

.


Questions and Answers
  • 1. 

    Can multiple catch blocks be executed?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
    Explanation
    No, Multiple catch blocks can’t be executed. Once the proper catch code executed, the control is transferred to the final block and then the code that follows the final block gets executed.

    Rate this question:

  • 2. 

    A=(5>6)?8:10 Consol.Writeline(a); what would be the output of this statement is a conditional statement.

    Correct Answer
    10
    Explanation
    The given statement is a conditional statement. It checks if the condition "5>6" is true or false. Since the condition is false, the value after the colon (10) is assigned to the variable A. Therefore, the output of the statement would be 10.

    Rate this question:

  • 3. 

    What actually manages your code?

    • A.

      JIT

    • B.

      CTS

    • C.

      CLR

    • D.

      CLS

    Correct Answer
    B. CTS
    Explanation
    The Common Type System (CTS) is responsible for managing code in the .NET framework. It defines how types are declared, used, and managed in the runtime environment. The CTS ensures type safety and interoperability between different languages in the .NET framework. It also provides metadata about types, which is used by the Common Language Runtime (CLR) for various purposes such as memory management and security. Therefore, the CTS is the correct answer as it is the component that actually manages code in the .NET framework.

    Rate this question:

  • 4. 

    Just-in-Time (JIT) Compilation: This is the term for the process of performing the ___ stage of compilation from IL into native machine code.

    • A.

      INTERMEDIATE

    • B.

      BEGINNING

    • C.

      FINAL

    • D.

      WHOLE

    Correct Answer
    A. INTERMEDIATE
    Explanation
    The correct answer is INTERMEDIATE because JIT compilation is the process of converting Intermediate Language (IL) code into native machine code at runtime. This means that the compilation happens just before the code is executed, allowing for optimizations based on the current state of the system. Therefore, the intermediate stage refers to the step where IL code is transformed into native machine code.

    Rate this question:

  • 5. 

    Using System; class emp { public string name; public string address; public void display() { Console.WriteLine("{0} is in city {1}", name, address); } } class Program { static void Main(string[] args) { emp obj = new emp(); obj.name = "Akshay"; obj.address = "new delhi"; obj.display(); Console.ReadLine(); } }

    • A.

      Syntax error

    • B.

      {0} is in city {1} Akshay new delhi

    • C.

      Akshay is in new delhi

    • D.

      Akshay is in city new delhi

    • E.

      Executes successfully and prints nothing

    Correct Answer
    D. Akshay is in city new delhi
    Explanation
    The given code defines a class "emp" with two public string variables "name" and "address" and a public method "display" that prints the name and address of an object of the "emp" class. In the Main method, an object "obj" of the "emp" class is created, its name and address are assigned, and the display method is called. The display method uses string formatting to print the name and address. The correct answer "Akshay is in city new delhi" is the correct output of the display method, as it correctly formats the name and address.

    Rate this question:

  • 6. 

    Shape obj; obj = new shape();

    • A.

      Creates an object of class shape.

    • B.

      To create an object of type shape on the heap or stack depending on its size.

    • C.

      Create a reference obj of the class shape and an object of type shape on the heap.

    • D.

      Create an object of type shape on the stack.

    Correct Answer
    C. Create a reference obj of the class shape and an object of type shape on the heap.
    Explanation
    The code "shape obj; obj = new shape();" creates a reference variable "obj" of the class "shape" and then creates an object of type "shape" on the heap using the "new" keyword. This means that the object is dynamically allocated in memory and can be accessed through the reference variable "obj". This is why the correct answer is "create a reference obj of the class shape and an object of type shape on the heap."

    Rate this question:

  • 7. 

    Using System; class sample { public static void first() { Console.WriteLine("first method"); } public void second() { first(); Console.WriteLine("second method"); } public void second(int i) { Console.WriteLine(i); second(); } } class program { public static void Main() { sample obj = new sample(); sample.first(); obj.second(10); } }

    • A.

      Second method 10 second method first method

    • B.

      First method 10 first method second method

    • C.

      First method 10

    • D.

      Second method 10 first method.

    Correct Answer
    B. First method 10 first method second method
    Explanation
    The correct answer is "first method 10 first method second method".

    In the given code, there is a class called "sample" with two methods: "first" and "second". The "first" method is a static method, meaning it can be called without creating an object of the class. The "second" method is an instance method, meaning it can only be called using an object of the class.

    In the "Main" method, an object of the "sample" class is created and assigned to the variable "obj". Then, the "first" method is called using the class name directly, which prints "first method" to the console.

    Next, the "second" method is called on the object "obj" with an argument of 10. This calls the second overload of the "second" method, which prints the value of the argument (10) and then calls the first overload of the "second" method. The first overload of the "second" method calls the "first" method again and then prints "second method" to the console.

    Therefore, the output is "first method 10 first method second method".

    Rate this question:

  • 8. 

    Using System; class program { static void Main(string[] args) { int num = 2; fun1 (ref num); Console.WriteLine(num); Console.ReadLine(); } static void fun1(ref int num) { num = num * num * num; } }

    • A.

      8

    • B.

      0

    • C.

      2

    • D.

      16

    Correct Answer
    A. 8
    Explanation
    The code provided defines a class called "program" with a method called "fun1" that takes an integer parameter by reference. In the Main method, an integer variable "num" is initialized with the value 2. The fun1 method is then called, passing the "num" variable as a reference. Inside the fun1 method, the value of "num" is updated by multiplying it by itself three times (2 * 2 * 2 = 8). Finally, the updated value of "num" is printed, which is 8.

    Rate this question:

  • 9. 

    Using System; class program { static void Main(string[] args) { int x = 8; int b = 16; int c = 64; x /= c /= b; Console.WriteLine(x + " " + b+ " " +c); Console.ReadLine(); } }

    • A.

      2 16 4

    • B.

      4 8 16

    • C.

      2 4 8

    • D.

      8 16 64

    Correct Answer
    A. 2 16 4
    Explanation
    The given code snippet demonstrates the use of compound assignment operators. The expression "x /= c /= b" is evaluated from right to left. First, "c /= b" is evaluated, which means "c = c / b", resulting in c = 4. Then, "x /= c" is evaluated, which means "x = x / c", resulting in x = 2. Therefore, the output of the code will be "2 16 4".

    Rate this question:

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.