Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

201.

Which of these iterators can be used only with List?(a) Setiterator(b) ListIterator(c) Literator(d) None of the mentioned

Answer» The correct choice is (b) ListIterator

For explanation: None.
202.

Which of the below is not a subinterface of Queue?(a) BlockingQueue(b) BlockingEnque(c) TransferQueue(d) BlockingQueue

Answer» The correct answer is (b) BlockingEnque

To explain I would say: BlockingQueue, TransferQueue and BlockingQueue are subinterfaces of Queue.
203.

Which of these is a method of ListIterator used to  obtain index of previous element?(a) previous()(b) previousIndex()(c) back()(d) goBack()

Answer» The correct choice is (b) previousIndex()

For explanation I would say: previousIndex() returns index of previous element. if there is no previous element then -1 is returned.
204.

What is use of wildcards?(a) It is used in cases when type being operated upon is not known(b) It is used to make code more readable(c) It is used to access members of super class(d) It is used for type argument of generic method

Answer» Right answer is (a) It is used in cases when type being operated upon is not known

Easy explanation: The wildcard can be used in a variety of situations: as the type of a parameter, field, or local variable; sometimes as a return type (though it is better programming practice to be more specific). The wildcard is never used as a type argument for a generic method invocation, a generic class instance creation, or a supertype.
205.

Which of the following is not an Enterprise Beans type?(a) Doubleton(b) Singleton(c) Stateful(d) Stateless

Answer» Right option is (a) Doubleton

Explanation: Stateful, Stateless and Singleton are session beans.
206.

What is the difference between length() and size() of ArrayList?(a) length() and size() return the same value(b) length() is not defined in ArrayList(c) size() is not defined in ArrayList(d) length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the list

Answer» Correct answer is (d) length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the list

Explanation: length() returns the capacity of ArrayList and size() returns the actual number of elements stored in the list which is always less than or equal to capacity.
207.

How is Arrays.asList() different than the standard way of initialising List?(a) Both are same(b) Arrays.asList() throws compilation error(c) Arrays.asList() returns a fixed length list and doesn’t allow to add or remove elements(d) We cannot access the list returned using Arrays.asList()

Answer» The correct answer is (c) Arrays.asList() returns a fixed length list and doesn’t allow to add or remove elements

Easiest explanation: List returned by Arrays.asList() is a fixed length list which doesn’t allow us to add or remove element from it.add() and remove() method will throw UnSupportedOperationException if used.
208.

Arrays in Java are implemented as?(a) class(b) object(c) variable(d) none of the mentioned

Answer» The correct option is (b) object

The explanation: None.
209.

Which of these is an correct way making a list that is upper bounded by class Number?(a) List

Answer» Right answer is (a) List

Explanation: None.
210.

Which of the below author is not a part of GOF (Gang of Four)?(a) Erich Gamma(b) Gang Pattern(c) Richard Helm(d) Ralph Johnson

Answer» Correct option is (b) Gang Pattern

The explanation: Four authors named Richard Helm, Erich Gamma, Ralph Johnson and John Vlissides published a book on design patterns. This book initiated the concept of Design Pattern in Software development. They are known as Gang of Four (GOF).
211.

Which of these is an incorrect Statement?(a) It is necessary to use new operator to initialize an array(b) Array can be initialized using comma separated expressions surrounded by curly braces(c) Array can be initialized when they are declared(d) None of the mentioned

Answer» Right answer is (a) It is necessary to use new operator to initialize an array

The best I can explain: Array can be initialized using both new and comma separated expressions surrounded by curly braces example : int arr[5] = new int[5]; and int arr[] = { 0, 1, 2, 3, 4};
212.

Which of these methods can be used to obtain a static array from an ArrayList object?(a) Array()(b) covertArray()(c) toArray()(d) covertoArray()

Answer» Correct answer is (c) toArray()

The explanation is: None.
213.

Which of these cannot be declared static?(a) class(b) object(c) variable(d) method

Answer» Right choice is (b) object

Easy explanation: static statements are run as soon as class containing then is loaded, prior to any object declaration.
214.

Which of these operators is used to allocate memory for an object?(a) malloc(b) alloc(c) new(d) give

Answer» The correct choice is (c) new

The explanation is: Operator new dynamically allocates memory for an object and returns a reference to it. This reference is address in memory of the object allocated by new.
215.

Which of the following is a valid declaration of an object of class Box?(a) Box obj = new Box();(b) Box obj = new Box;(c) obj = new Box();(d) new Box obj;

Answer» Correct choice is (a) Box obj = new Box();

Explanation: None.
216.

What is the process of defining two or more methods within same class that have same name but different parameters declaration?(a) method overloading(b) method overriding(c) method hiding(d) none of the mentioned

Answer» The correct choice is (a) method overloading

For explanation I would say: Two or more methods can have same name as long as their parameters declaration is different, the methods are said to be overloaded and process is called method overloading. Method overloading is a way by which Java implements polymorphism.
217.

Which of these is an incorrect array declaration?(a) int arr[] = new int[5](b) int [] arr = new int[5](c) int arr[] = new int[5](d) int arr[] = int [5] new

Answer» Correct choice is (d) int arr[] = int [5] new

Easy explanation: Operator new must be succeeded by array type and array size.
218.

Which of the below is not a valid design pattern?(a) Singleton(b) Factory(c) Command(d) Java

Answer» The correct answer is (d) Java

To elaborate: Design pattern is a general repeatable solution to a commonly occurring problem in software design. There are various patterns available for use in day to day coding problems.
219.

Which of the following is the correct way of implementing an interface A by class B?(a) class B extends A{}(b) class B implements A{}(c) class B imports A{}(d) None of the mentioned

Answer» The correct answer is (b) class B implements A{}

Easiest explanation: Concrete class implements an interface. They can be instantiated.
220.

Which of the following is the correct way of implementing an interface salary by class manager?(a) class manager extends salary {}(b) class manager implements salary {}(c) class manager imports salary {}(d) none of the mentioned

Answer» The correct choice is (b) class manager implements salary {}

To explain I would say: None.
221.

Which of the following is used for implementing inheritance through class?(a) inherited(b) using(c) extends(d) implements

Answer» The correct option is (c) extends

For explanation: Class can be extended using extends keyword. One class can extend only one class. A final class cannot be extended.
222.

Which of this method of class StringBuffer is used to reverse sequence of characters?(a) reverse()(b) reverseall()(c) Reverse()(d) reverseAll()

Answer» The correct answer is (a) reverse()

For explanation: reverse() method reverses all characters. It returns the reversed object on which it was called.
223.

Which of this method of class StringBuffer is used to get the length of the sequence of characters?(a) length()(b) capacity()(c) Length()(d) Capacity()

Answer» The correct choice is (a) length()

For explanation: length()- returns the length of String the StringBuffer would create whereas capacity() returns a total number of characters that can be supported before it is grown.
224.

Which of these classes is not included in java.lang?(a) Byte(b) Integer(c) Array(d) Class

Answer» Correct answer is (c) Array

Easiest explanation: Array class is a member of java.util.
225.

Which class does all the Enums extend?(a) Object(b) Enums(c) Enum(d) EnumClass

Answer» Right choice is (c) Enum

Easiest explanation: All enums implicitly extend java.lang.Enum. Since Java does not support multiple inheritance, an enum cannot extend anything else.
226.

What does setAutoCommit(false) do?(a) commits transaction after each query(b) explicitly commits transaction(c) does not commit transaction automatically after each query(d) never commits transaction

Answer» Correct choice is (c) does not commit transaction automatically after each query

To explain I would say: setAutoCommit(false) does not commit transaction automatically after each query. That saves a lot of time of the execution and hence improves performance.
227.

Which function is used to  perform some action when the object is to be destroyed?(a) finalize()(b) delete()(c) main()(d) none of the mentioned

Answer» Right choice is (a) finalize()

Easiest explanation: None.
228.

Which of the following is not provided by BigDecimal?(a) scale manipulation(b) + operator(c) rounding(d) hashing

Answer» Right option is (b) + operator

Best explanation: toBigInteger() converts BigDecimal to a BigInteger.toBigIntegerExact() converts this BigDecimal to a BigInteger by checking for lost information.
229.

What is true about threading?(a) run() method calls start() method and runs the code(b) run() method creates new thread(c) run() method can be called directly without start() method being called(d) start() method creates new thread and calls code written in run() method

Answer» Correct choice is (d) start() method creates new thread and calls code written in run() method

The best explanation: start() eventually calls run() method. Start() method creates thread and calls the code written inside run method.
230.

Which of the following is a correct constructor for thread?(a) Thread(Runnable a, String str)(b) Thread(int priority)(c) Thread(Runnable a, int priority)(d) Thread(Runnable a, ThreadGroup t)

Answer» Right answer is (a) Thread(Runnable a, String str)

Explanation: Thread(Runnable a, String str) is a valid constructor for thread. Thread() is also a valid constructor.
231.

Which of the following contains both date and time?(a) java.io.date(b) java.sql.date(c) java.util.date(d) java.util.dateTime

Answer» Correct answer is (d) java.util.dateTime

Easiest explanation: java.util.date contains both date and time. Whereas, java.sql.date contains only date.
232.

BigDecimal is a part of which package?(a) java.lang(b) java.math(c) java.util(d) java.io

Answer» The correct option is (b) java.math

To elaborate: BigDecimal is a part of java.math. This package provides various classes for storing numbers and mathematical operations.
233.

What does LocalTime represent?(a) Date without time(b) Time without Date(c) Date and Time(d) Date and Time with timezone

Answer» Correct answer is (b) Time without Date

For explanation: LocalTime of joda library represents time without date.
234.

What is the replacement of joda time library in java 8?(a) java.time (JSR-310)(b) java.date (JSR-310)(c) java.joda(d) java.jodaTime

Answer» The correct choice is (a) java.time (JSR-310)

The explanation: In java 8, we are asked to migrate to java.time (JSR-310) which is a core part of the JDK which replaces joda library project.
235.

Which of the following should be true of the object thrown by a thrown statement?(a) Should be assignable to String type(b) Should be assignable to Exception type(c) Should be assignable to Throwable type(d) Should be assignable to Error type

Answer» The correct choice is (c) Should be assignable to Throwable type

The best I can explain: The throw statement should be assignable to the throwable type. Throwable is the super class of all exceptions.
236.

Which of these class is related to all the exceptions that can be caught by using catch?(a) Error(b) Exception(c) RuntimeExecption(d) All of the mentioned

Answer» Right answer is (b) Exception

For explanation: Error class is related to java run time error that can’t be caught usually, RuntimeExecption is subclass of Exception class which contains all the exceptions that can be caught.
237.

Which of these is a super class of all exceptional type classes?(a) String(b) RuntimeExceptions(c) Throwable(d) Cacheable

Answer» The correct choice is (c) Throwable

Easiest explanation: All the exception types are subclasses of the built in class Throwable.
238.

Which of these methods can be used to determine the type of event?(a) getID()(b) getSource()(c) getEvent()(d) getEventObject()

Answer» Correct answer is (a) getID()

The best I can explain: getID() can be used to determine the type of an event.
239.

Which of these events will be notified if scroll bar is manipulated?(a) ActionEvent(b) ComponentEvent(c) AdjustmentEvent(d) WindowEvent

Answer» Right answer is (c) AdjustmentEvent

To elaborate: AdjustmentEvent is generated when a scroll bar is manipulated.
240.

Which of the below is not a Java Profiler?(a) JVM(b) JConsole(c) JProfiler(d) Eclipse Profiler

Answer» Right answer is (a) JVM

The best explanation: Memory leak is like holding a strong reference to an object although it would never be needed anymore. Objects that are reachable but not live are considered memory leaks. Various tools help us to identify memory leaks.
241.

Which of these class is super class of all the events?(a) EventObject(b) EventClass(c) ActionEvent(d) ItemEvent

Answer» Correct choice is (a) EventObject

The explanation is: EventObject class is a super class of all the events and is defined in java.util package.
242.

Which one of the following causes memory leak?(a) Release database connection when querying is complete(b) Use Finally block as much as possible(c) Release instances stored in static tables(d) Not using Finally block often

Answer» Correct option is (d) Not using Finally block often

To explain I would say: Finally block is called in successful as well exception scenarios. Hence, all the connections are closed properly which avoids memory leak.
243.

Which of the below is not a memory leak solution?(a) Code changes(b) JVM parameter tuning(c) Process restart(d) GC parameter tuning

Answer» Correct choice is (c) Process restart

The explanation: Process restart is not a permanent fix to memory leak problem. The problem will resurge again.
244.

Which data structure is used in Breadth First Traversal of a graph?(a) Stack(b) Queue(c) Array(d) Tree

Answer» Right choice is (b) Queue

The explanation: In Breadth First Traversal of graph the nodes at the same level are accessed in the order of retrieval (i.e FIFO).
245.

Which of these class contains all the methods present in Math class?(a) SystemMath(b) StrictMath(c) Compiler(d) ClassLoader

Answer» The correct choice is (b) StrictMath

Easy explanation: SystemMath class defines a complete set of mathematical methods that are parallel those in Math class. The difference is that the StrictMath version is guaranteed to generate precisely identical results across all Java implementations.
246.

Which of these methods is used to know whether a string contains “true”?(a) valueOf()(b) valueOfString()(c) getString()(d) none of the mentioned

Answer» Right answer is (a) valueOf()

Best explanation: valueOf() returns true if the specified string contains “true” in lower or uppercase and false otherwise.
247.

Where is a new object allocated memory?(a) Young space(b) Old space(c) Young or Old space depending on space availability(d) JVM

Answer» Correct option is (a) Young space

Easiest explanation: A new object is always created in young space. Once young space is full, a special young collection is run where objects which have lived long enough are moved to old space and memory is freed up in young space for new objects.
248.

Which of these packages contains all the event handling interfaces?(a) java.lang(b) java.awt(c) java.awt.event(d) java.event

Answer» The correct answer is (c) java.awt.event

The explanation: None.
249.

Event class is defined in which of these libraries?(a) java.io(b) java.lang(c) java.net(d) java.util

Answer» Correct answer is (d) java.util

Explanation: None.
250.

Which of these class produce objects with respect to geographical locations?(a) TimeZone(b) Locale(c) Date(d) SimpleTimeZone

Answer» The correct choice is (b) Locale

To elaborate: The Locale class isinstantiated to produce objects that each describe a geographical or cultural region.