TATA ELXSI Previous Years Solved Sample Placement Papers
-
What is the use of 'throw' statement in C#?
A: to return from the calling functions to called function
B: to throw an exception manually during the execution of the program
C: to return from the switch statement
D: None of the above
Ans: BExplanation:
The C# throw statement is used to throw an exception manually during the execution of the program.
-
What will be the output of the following C# code?
using System; class Program { static void Main(string[] args) { String str = "Hello"; Console.WriteLine(str.IndexOf('h')); } }
A: 0
B: 1
C: -1
D: Error
Ans: CExplanation:
The IndexOf() method returns the index of a given character, and it returns -1 if the given character is not found in the string. Here, we are trying to get the index of 'h' which is not present in the string. Thus, the output will be -1.
-
To declare an array, define the variable type with ___.
A: Square brackets []
B: Curly brackets {}
C: Round brackets ()
D: None of the above
Ans: AExplanation:
To declare an array, define the variable type with square brackets [].
-
What will be the output of the following C# code?
using System; namespace MyApplication { class Program { static void Main(string[] args) { string[] mobiles = { "iPhone", "Samsung", "Vivo"}; Console.WriteLine(mobiles); } } }
A: "iPhone", "Samsung", "Vivo"
B: {"iPhone", "Samsung", "Vivo"}
C: string[]
D: System.String[]
Ans: DExplanation:
In the above code, the statement
Console.WriteLine(mobiles);
will print the type of the variable that isSystem.String[]
. -
What will be the output of the following C# code?
using System; namespace MyApplication { class Program { static void Main(string[] args) { string[] mobiles = {"iPhone", "Samsung", "Vivo"}; Console.WriteLine(mobiles[-1]); } } }
A: None
B: Warning
C: Exception
D: System.String[]
Ans: CExplanation:
The array index starts from 0 in C#. In the above code, we are trying to access an element with index -1, resulting in an exception:
System.IndexOutOfRangeException
. -
Which statement is correct about the following C# statement?
int[] x = {10, 20, 30};
A: 'x' is a reference to the array created on stack
B: 'x' is a reference to an object created on stack
C: 'x' is a reference to an object of a 'System.Array' class
D: None of the above
Ans: CExplanation:
In the above given C# statement, the variable
x
is a reference to an object of aSystem.Array
class. -
Which array property is used to get the total number of elements in C#?
A: Len
B: Length
C: Elements
D: MaxLen
Ans: BExplanation:
The
Length
property is used to get the total number of elements in C#. -
Which operator is used to access variables/fields inside a class in C#?
A: Arrow Operator (->)
B: Dot Operator (.)
C: Greater Than (>)
D: Dot and Greater Than (.>)
Ans: BExplanation:
The dot (
.
) operator is used to access variables/fields in a class in C#.Syntax: Class_Name.Variable_Name/Field_Name;
-
Is overriding of a function possible in the same class in C#?
A: Yes
B: No
Ans: BExplanation:
No, overriding of a function is not possible in the same class in C#. The
override
modifier is required to extend or modify the implementation of an inherited method. -
Which is not a type of constructor in C#?
A: Static Constructor
B: Private Constructor
C: Body Constructor
D: Parameterized Constructor
Ans: CExplanation:
There are 5 types of constructors in C#: Static, Private, Copy, Default, and Parameterized constructors.
-
How many types of access modifiers in C#?
A: 2
B: 3
C: 4
D: 5
Ans: CExplanation:
In C#, there are 4 types of access modifiers: public, private, protected, and internal.
-
What does the access modifier do in C#?
A: To maintain the syntax
B: To define a variable inside the class
C: To access the variables defined inside the class
D: To control the visibility of class members
Ans: DExplanation:
Access modifiers control the visibility of class members, providing a security level for each individual class and member.
-
The internal access modifier is used for ___.
A: Types and type members
B: Defining a field that can be accessed in all classes
C: Defining a field that can be accessed in inherited classes
D: All of the above
Ans: AExplanation:
The internal access modifier is used for types and type members. They are accessible only within files in the same assembly.