Mphasis Previous Years Solved Sample Placement Papers
-
What is the key difference between a while loop and a do-while loop in Java?
A: The syntax used to define the loop
B: The number of iterations performed
C: The condition check timing
D: The ability to use the break statement
Ans: C -
Which loop construct guarantees that the loop body is executed at least once?
A: for loop
B: while loop
C: do-while loop
D: continue statement
Ans: C -
What is an infinite loop?
A: A loop that executes only once
B: A loop that never terminates naturally
C: A loop that contains an unreachable code block
D: A loop that uses the continue statement
Ans: B -
Which statement is used to exit a loop prematurely?
A: return statement
B: continue statement
C: break statement
D: exit statement
Ans: C -
Which loop construct is best suited for iterating over an array or a collection?
A: for loop
B: while loop
C: do-while loop
D: continue statement
Ans: A -
How do you declare an array in Java?
A: int arrayName;
B: int[] arrayName;
C: int arrayName[];
D: Both b and c
Ans: D -
Which method is used to get the length of an array in Java?
A: length()
B: size()
C: getLength()
D: length
Ans: D -
How do you initialize an array in Java?
A: int[] arr = (1,2,3,4,5);
B: int arr = {1,2,3,4,5};
C: int[] arr = new int[]{1,2,3,4,5};
D: int arr = new int(5);
Ans: C -
What happens when you try to access an array element with an index that is out of bounds?
A: It returns -1
B: It returns a null value
C: It throws an exception
D: It initializes a new array
Ans: C -
How can you check if two arrays are equal in Java?
A: Use the == operator
B: Use the .equals() method
C: Use Arrays.equals() method
D: Compare each element one by one
Ans: C -
How do you access the fourth element of an array named numbers?
A: numbers[4];
B: numbers(3);
C: numbers[3];
D: numbers.get(3);
Ans: C -
Which of the following operators is used for concatenation of two strings?
A: +
B: *
C: &
D: +=
Ans: A -
Which of the following creates a mutable string?
A: String
B: StringBuilder
C: StringChar
D: StringMutable
Ans: B -
In Java, strings are:
A: Primitive data types
B: Immutable objects
C: Mutable objects
D: Arrays of characters
Ans: B -
How do you find the length of a string named 'example'?
A: example.size()
B: example.length()
C: example.getLength()
D: example.len()
Ans: B -
What is the result of the expression "Java" + "Programming"?
A: JavaProgramming
B: Java Programming
C: Java-Programming
D: JavaProgramming-
Ans: A -
Which method is used to compare two strings for equality?
A: ==
B: equals()
C: compare()
D: isEqual()
Ans: B -
Which class can create a string that is thread-safe?
A: String
B: StringBuffer
C: StringBuilder
D: StringSafe
Ans: B -
What is the root class for all Java classes?
A: Object
B: Class
C: Superclass
D: Root
Ans: A -
What is polymorphism?
A: Multiple forms
B: Single form
C: No form
D: Static form
Ans: A -
What is encapsulation in Java?
A: The process of combining data and methods into a single unit
B: The process of hiding data and methods within a class
C: The process of creating multiple instances of a class
D: The process of reusing code from existing classes
Ans: B -
What is inheritance in Java?
A: The process of creating multiple instances of a class
B: The process of hiding data and methods within a class
C: The process of reusing code from existing classes
D: The process of combining data and methods into a single unit
Ans: C -
What is polymorphism in Java?
A: The ability of a class to inherit properties and behaviors from another class
B: The process of hiding data and methods within a class
C: The process of creating multiple instances of a class
D: The ability of an object to take on many forms
Ans: D