1.
Can multiple catch blocks be executed?
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.
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.
3.
What actually manages your code?
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.
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.
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.
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(); } }
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.
6.
Shape obj; obj = new shape();
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."
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); } }
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".
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; } }
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.
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(); } }
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".