1.
Does c# support multiple inheritance?
Correct Answer
B. No
Explanation
Multiple inheritance is not supported. To achieve this, use interfaces.
2.
How do you keep your classes from being inherited or used as a base class?
Correct Answer
C. Declare the class as Sealed
Explanation
Sealed. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName.
3.
Can you inherit from multiple interfaces?
Correct Answer
A. Yes
Explanation
Yes, it is possible to inherit from multiple interfaces in programming languages that support multiple inheritance. This allows a class to inherit and implement the methods and properties defined in multiple interfaces, providing flexibility and the ability to fulfill multiple contracts. This feature is commonly used to achieve code reusability and to create more modular and flexible code structures.
4.
Which is true about the accessibility modifiers of methods within an Interface?
Correct Answer
A. They are all declared as public by default
Explanation
The accessibility modifiers of methods within an Interface are all declared as public by default. This means that all methods within an Interface can be accessed and called from any other class or interface. There is no need to explicitly specify the public modifier for methods within an Interface as it is automatically assumed.
5.
What are the different ways to overload a method?
Correct Answer(s)
B. Different parameter data types
C. Different number of parameters
D. Different ordering of parameters
Explanation
The different ways to overload a method include using different parameter data types, different number of parameters, and different ordering of parameters. Overloading a method allows for multiple methods with the same name but different parameters, providing flexibility and versatility in method usage. By using different parameter data types, different number of parameters, or different ordering of parameters, we can create different versions of the method that can be called based on the specific arguments provided. This allows for more efficient and concise code, as well as accommodating various input scenarios.
6.
What is the difference between the System.String and System.StringBuilder class?
Correct Answer
B. System.StringBuilder is mutable and System.String is immutable
Explanation
The correct answer is that System.StringBuilder is mutable and System.String is immutable. This means that the value of a System.String object cannot be changed after it is created, while a System.StringBuilder object can be modified.
7.
Structs are passed by Reference?
Correct Answer
B. False
Explanation
Structs cannot be inherited.
Structs are passed by value, not by reference.
Struct is stored on the stack, not the heap.
8.
You have variable of type string name strValue. What are some of the ways this can be converted to a int?
Correct Answer(s)
B. Convert.ToInt32(strValue)
C. Int32.Parse(strValue)
E. Bool result = int32.TryParse(strValue, out i)
Explanation
The given answer lists three methods to convert a string to an integer: Convert.ToInt32(strValue), int32.Parse(strValue), and bool result = int32.TryParse(strValue, out i).
Convert.ToInt32(strValue) is a method in C# that converts the specified string representation of a number to an equivalent 32-bit signed integer.
int32.Parse(strValue) is another method in C# that converts the string representation of a number to its 32-bit signed integer equivalent.
int32.TryParse(strValue, out i) is a method in C# that attempts to convert the string representation of a number to its 32-bit signed integer equivalent. It returns a boolean value indicating whether the conversion succeeded or failed, and the converted value is assigned to the out parameter 'i'.
9.
How do you enforce garbage collection in .NET?
Correct Answer
D. System.GC.Collect()
Explanation
In .NET, the System.GC.Collect() method is used to enforce garbage collection. This method forces an immediate garbage collection of all generations. It can be called explicitly to free up memory and reclaim resources that are no longer needed. The other options mentioned, Garbage.Collect(), Collect(), and this.Collect.Garbage(), are not valid methods for enforcing garbage collection in .NET.