Correct Answers 2025/2026 Updated.
What is the output of this program?
class Test {
public static void main(String[] args){
HashSet set = new HashSet();
set.add("ABC");
set.add("ABC");
set.add("CDF");
Iterator iterator = set.iterator();
while(iterator.hasNext())
{
System.out.println(iterator.next().toString()); break;
}
}
}
a. Compile error
b. ABCABC
CDF
c. ABCCDF
d. ABC - Answer d.
How many finally blocks can there be in a try/catch structure?
Select one:
a. There can be 0 or 1 following the last catch block.
b. There must be 1.
c. There is no limit to the number of finally blocks following the last catch block.
d. There can be 1 following each catch block. - Answer a.
What is the output of this program?
class Test {
public static void main(String[] args){
String str1 = "ABC");
String str2 = "ABC";
,System.out.println(str1==str2);
}
}
Select one:
a. true
b. false - Answer a.
Which one of the following is not true?
Select one:
a. Abstract methods should be implemented in the derived class.
b. A class containing abstract methods is called an abstract class.
c. An abstract class cannot have non-abstract methods.
d. A class must be qualified as 'abstract' class, if it contains one abstract method.
e. None of the above. - Answer c.
What modifier is to be used If you wish to declare that you want to no longer allow subclasses
to override your variables or methods?
Select one:
a. synchronized
b. final
c. volatile
d. finally
e. abstract - Answer b.
Consider the following class definition:
public class MyClass
{
private int value;
public void setValue(int i){ /* code */ }
// Other methods...
}
The method setValue assigns the value of i to the instance field value. What could you write for
the implementation of setValue?
Select one:
a. III. value == i;
,b. Both (I) and (II) and above
c. (I), (II) and (III) above.
d. II. this.value = i;
e. I. value = i; - Answer b.
Consider the following program written in Java.
class Selection{
public static void main(String args[]){
int x=7;
if(x==2); //? Note the semicolon
System.out.println("Number seven");
System.out.println("Not seven");
}
}
What would the output of the program be?
Select one:
a. Number sevenNot seven
b. 7
c. Number seven
d. Not seven
e. Error - Answer a.
InputStream class is an ________
Select one:
a. base class
b. interface
c. class
d. abstract class - Answer d.
A collection is a container that helps to group multiple elements of Object class into a single unit
Select one:
a. FALSE
b. TRUE - Answer a.
Which access specifiers should be implemented in a class for all interface methods?
, I. private.
II. public.
III. protected.
Select one:
a. Only (I) above
b. Only (III) above
c. All (I), (II) and (III) above.
d. Both (I) and (III) above
e. Only (II) above - Answer e.
char chars[] = { 'a', 'b', 'c', 'd', 'e', 'f'};
String s = new String(chars, 2, 3);
System.out.println (s);
What is the output of the above code?
Select one:
a. abc
b. bcd
c. acd.
d. deb
e. cde - Answer e.
What is the error in the following class definitions?
abstract class xy
{
abstract sum (int x, int y) { }
}
Select one:
a. Method is not defined properly
b. Class header is not defined properly.
c. Method is defined properly
d. No error.
e. Constructor is not defined. - Answer a.
Given Main class
class Main {