Mphasis Previous Years Solved Sample Placement Papers
-
Which keyword is used to define a class in C#?
A: Class
B: class
C: System.Class
D: OOPS.class
Ans: BExplanation:
The
class
keyword is used to define a class in C#.Syntax: class class_name { // Class Definition }
-
Which is the correct way to declare an object of the class in C#?
A:
Class_Name Object_Name = new Class_Name();
B:
Class_Name Object_Name;
C:
new Object_Name as Class_Name();
D: Both A and B
Ans: AExplanation:
The correct way to declare an object of the class in C# is:
Class_Name Object_Name = new Class_Name();
Example:
using System; namespace MyApplication { class Mobiles { string brand = "Apple"; static void Main(string[] args) { Mobiles mobile = new Mobiles(); Console.WriteLine(mobile.brand); } } } // Output: Apple
-
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.
-
The protected access modifier defines a member that can be accessible within ___.
A: its class and all other classes
B: its class and by derived class instances
C: its class only
D: None of the above
Ans: BExplanation:
The protected access modifier defines a member that can be accessible within its class and by derived class instances.
-
Does C# support multiple inheritance?
A: Yes
B: No
Ans: BExplanation:
No, C# does not support multiple class inheritance.
-
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
D: None of the above
Ans: AExplanation:
Polymorphism allows an object to take on multiple forms and display different behaviors accordingly.
-
What will be the output of the following C# code?
using System; namespace MyApplication { public class Class1 { public static int x = 10; } public class Class2: Class1 { public static int x = 20; static void Main(string[] args) { Console.WriteLine(x + ", " + Class1.x); } } }
A: 20, 20
B: 10, 10
C: 20, 10
D: Exception
Ans: CExplanation:
The code prints the value of
x
inClass2
andClass1.x
, resulting in "20, 10". -
What is the C# keyword which is used to change data and behavior of a base class by replacing a member of the base class with a new derived member?
A: overrides
B: protected
C: base
D: new
Ans: DExplanation:
The
new
keyword is used to change data and behavior of a base class by replacing a member with a new derived member.