- 1
- 2
- 3
- 4
- Next Page »
A Learning Portal from Recruitment India
Which of these classes can return more than one character to be returned to the input stream?
BufferedReader
Bufferedwriter
PushbachReader
CharArrayReader
Answer with explanation
Answer: Option CExplanation
PushbackReader class allows one or more characters to be returned to the input stream. This allows looking ahead in the input stream and performing action accordingly.
Workspace
What will be the result of compiling and running the given code?
class A{
int b=10;
private A(){
this.b=7;
}
int f(){
return b;
}
}
class B extends A{
int b;
}
public class Test{
public static void main(String[] args){
A a = new B();
System.out.println(a.f());
}
}
Prints 7
Prints 10
Prints 0
Compilation fails
Answer with explanation
Answer: Option DExplanation
The code does not compile because the constructor of class A is declared as private. This creates a problem when the subclass constructor makes an implicit super() call to the parent class constructor at the time B is instantiated.
Since the code does not compile, all the other choices are incorrect. If the constructor of A had not been private, the output would have been 7.
Workspace
Which of the following declares an abstract method in an abstract Java class?
public abstract method();
public abstract void method();
public void abstract Method();
public void method() {}
Answer with explanation
Answer: Option BExplanation
public abstract void method();
Workspace
How are you able to sort given HashMap on the basis of values.
Implement the Comparator interface and override its compare method
Implement Comparator and Comparable interface
It is not possible
Implement the Comparator interface and override its compareTo method
Answer with explanation
Answer: Option AExplanation
Implement the Comparator interface and override its compare method
Workspace
Which of these methods can be used to output a sting in an applet?
display()
print()
drawString()
transient()
Answer with explanation
Answer: Option CExplanation
drawString() method is defined in Graphics class, it is used to output a string in an applet.
Workspace
Which of the following does not belong: If a class inherits from some other class, it should
Over-ride all the methods of its parent class
Make use of the parent class’s capabilities
Over-ride or add the minimum to accomplish the derived class’ purpose
Make sure the result “IS-A-KIND-OF” its base class
Answer with explanation
Answer: Option AExplanation
Over-ride all the methods of its parent class
Workspace
Which of the following code segment would execute the stored procedure “getPassword()” located in a database server?
CallableStatement cs = connection.prepareCall(“{call.getPassword()}”);
cs.executeQuery();
CallabledStatement callable = conn.prepareCall(“{call getPassword()}”);
callable.executeUpdate();
CallableStatement cab = con.prepareCall(“{call getPassword()}”);
cab.executeQuery();
Callablestatement cstate = connect.prepareCall(“{call getpassword()}”);
cstate.executeQuery();
Answer with explanation
Answer: Option CExplanation
In Java, java.sql.CallableStatement interface is used to call the SQL stored procedures in the database. The stored procedures are similar to functions as they perform some specific tasks, except that they are only available in the database. The CallableStatement can return either a single ResultSet object or multiple ResultSet objects.
CallableStatement cab = con.prepareCall(“{call getPassword()}”);
cab.executeQuery();
Workspace
Which of the following is a valid syntax to synchronize the HashMap?
Map m = hashMap.synchronizeMap();
HashMap map =hashMap.synchronizeMap();
Map m1 = Collections.synchronizedMap(hashMap);
Map m2 = Collection.synchronizeMap(hashMap);
Answer with explanation
Answer: Option CExplanation
By default, the HashMap class is a non-synchronized collection class. The need for synchronization is to perform thread-safe operations on the class. To synchronize the HashMap class explicitly, we should use the Collections.synchronizedMap(hashMap) method that returns a thread-safe map object.
Map m1 = Collections.synchronizedMap(hashMap);
Workspace
Which of the following class definitions defines a legal abstract class?
class A { abstract void unfinished() { } }
class A { abstract void unfinished(); }
abstract class A { abstract void unfinished(); }
public class abstract A { abstract void unfinished(); }
Answer with explanation
Answer: Option CExplanation
Workspace
Which statement is not true in java language?
A public member of a class can be accessed in all the packages.
A private member of a class cannot be accessed by the methods of the same class.
A private member of a class cannot be accessed from its derived class.
A protected member of a class can be accessed from its derived class
Answer with explanation
Answer: Option BExplanation
A private member of a class cannot be accessed by the methods of the same class.
Workspace