1. Which of these methods can be used to convert all characters in a String into a character array?
a) CharAt()
b) getChars()
c) TocharArray()
d) All of the mentioned
Explanation: TocharArray()
2. What will be the output of the following C# code snippet?
static void main(String args[])
{
char chars[] = {'x', 'y', 'z'};
String s = new String(chars);
Console.WriteLine(s);
}
a) x
b) xy
c) z
d) xyz
Explanation: String(chars) is a constructor of class string, it initializes string s with the values stored in character array chars, therefore s contains “xyz”.
Output :
xyz
3. Which of these methods of class String is used to extract all the characters from a String object?
a) CHARAT()
b) Remove()
c) charAt()
d) Replace()
Explanation: Replace() replaces all instances of a character with a new character while Remove extracts characters from the string.
4. What will be the output of the following C# code snippet?
static void Main(string[] args)
{
string c = "hello";
string c1 = c.Remove(1);
Console.WriteLine(c1);
Console.ReadLine();
}
a) ello
b) h
c) hell
d) none of the mentioned
Explanation: The remove() deletes characters from the string except the character which is specified with its given position.
Output :
h
5. How is a string typically processed?
a) On a character by character basis
b) On a string by string basis
c) Both On a character by character basis & On a string by string basis
d) None of the mentioned
Explanation: On a character by character basis
6. How to print \\ on the screen?
a) Console.WriteLine(“\\”);
b) Console.WriteLine(“\\\”);
c) Console.WriteLine(“\\\\”);
d) Console.WriteLine(“\\\\\\”);
Explanation: Console.WriteLine(“\\\\”);
Output :
\\
7. Which of these is used as a default specifier for a member of the class if no access specifier is used for it?
a) private
b) public
c) public, within its own class
d) protected
Explanation: By definition if a class has no access specifiers, it defaults to private accessibility.
8. Which of these is used to access members of class before the object of that class is created?
a) public
b) private
c) static
d) protected
Explanation: static
9. Which of these base classes are accessible to the derived class members?
a) static
b) protected
c) private
d) Shared
Explanation: protected
10. What is the process by which we can control parts of a program that can access the members of a class?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion
Explanation: Encapsulation