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.

1.

Which of these exceptions will be thrown if we declare an array with negative size?(a) IllegalArrayException(b) IllegalArraySizeExeption(c) NegativeArrayException(d) NegativeArraySizeExeption

Answer» Right choice is (d) NegativeArraySizeExeption

Easiest explanation: Array size must always be positive if we declare an array with negative size then built in exception “NegativeArraySizeException” is thrown by the java’s run time system.
2.

Which of these handles the exception when no catch is used?(a) Default handler(b) finally(c) throw handler(d) Java run time system

Answer» Right choice is (a) Default handler

Explanation: None.
3.

Which of the following handles the exception when a catch is not used?(a) finally(b) throw handler(c) default handler(d) java run time system

Answer» Right option is (c) default handler

Easiest explanation: Default handler is used to handle all the exceptions if catch is not used to handle exception. Finally is called in any case.
4.

Which design pattern ensures that only one object of particular class gets created?(a) Singleton pattern(b) Filter pattern(c) State pattern(d) Bridge pattern

Answer» Right answer is (a) Singleton pattern

To elaborate: Singleton pattern involves a single class which is responsible to create an object while making sure that only one object gets created. This class provides a way to access the only object which can be accessed directly without need to instantiate another object of the same class.
5.

Which of the following operators is used to generate instance of an exception which can be thrown using throw?(a) thrown(b) alloc(c) malloc(d) new

Answer» Right choice is (d) new

For explanation I would say: new operator is used to create instance of an exception. Exceptions may have parameter as a String or have no parameter.
6.

Which of these exceptions handles the situations when an illegal argument is used to invoke a method?(a) IllegalException(b) Argument Exception(c) IllegalArgumentException(d) IllegalMethodArgumentExcepetion

Answer» Right answer is (c) IllegalArgumentException

The best explanation: None.
7.

How do we pass command line argument in Eclipse?(a) Arguments tab(b) Variable tab(c) Cannot pass command line argument in eclipse(d) Environment variable tab

Answer» The correct answer is (a) Arguments tab

Explanation: Arguments tab is used to pass command line argument in eclipse.
8.

On applying Left shift operator,

Answer» Right option is (d) 31

Explanation: The left shift operator shifts all of the bits in a value to the left specified number of times. For each shift left, the high order bit is shifted out and lost, zero is brought in from the right. When a left shift is applied to an integer operand, bits are lost once they are shifted past the bit position 31.
9.

Which of these is correct about passing an argument by call-by-value process?(a) Copy of argument is made into the formal parameter of the subroutine(b) Reference to original argument is passed to formal parameter of the subroutine(c) Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument(d) Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument

Answer» Correct option is (a) Copy of argument is made into the formal parameter of the subroutine

For explanation: When we pass an argument by call-by-value a copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have no effect on original argument, they remain the same.
10.

Which of these operator is used to generate an instance of an exception than can be thrown by using throw?(a) new(b) malloc(c) alloc(d) thrown

Answer» Right choice is (a) new

Easy explanation: new is used to create an instance of an exception. All of java’s built in run-time exceptions have two constructors: one with no parameters and one that takes a string parameter.
11.

Which of these is used to access a member of class before object of that class is created?(a) public(b) private(c) static(d) protected

Answer» The correct choice is (c) static

For explanation: None.
12.

Which of these is not a bitwise operator?(a) &(b) &=(c) |=(d)

Answer» Right option is (d) <=

Best explanation: <= is a relational operator.
13.

Which of these access specifiers must be used for main() method?(a) private(b) public(c) protected(d) none of the mentioned

Answer» The correct choice is (b) public

Easiest explanation: main() method must be specified public as it called by Java run time system, outside of the program. If no access specifier is used then by default member is public within its own package & cannot be accessed by Java run time system.
14.

Modulus operator, %, can be applied to which of these?(a) Integers(b) Floating – point numbers(c) Both Integers and floating – point numbers(d) None of the mentioned

Answer» The correct option is (c) Both Integers and floating – point numbers

For explanation: Modulus operator can be applied to both integers and floating point numbers.
15.

Which of these access specifiers can be used for an interface?(a) Public(b) Protected(c) private(d) All of the mentioned

Answer» The correct answer is (a) Public

Explanation: Access specifier of an interface is either public or no specifier. When no access specifier is used then default access specifier is used due to which interface is available only to other members of the package in which it is declared, when declared public it can be used by any code.
16.

Which of these stream contains the classes which can work on character stream?(a) InputStream(b) OutputStream(c) Character Stream(d) All of the mentioned

Answer» The correct answer is (c) Character Stream

Easiest explanation: InputStream & OutputStream classes under byte stream they are not streams. Character Stream contains all the classes which can work with Unicode.
17.

Which of these interface extends DataOutput interface?(a) Serializable(b) Externalization(c) ObjectOutput(d) ObjectInput

Answer» Right choice is (c) ObjectOutput

The explanation is: ObjectOutput interface extends the DataOutput interface and supports object serialization.
18.

How an object can become serializable?(a) If a class implements java.io.Serializable class(b) If a class or any superclass implements java.io.Serializable interface(c) Any object is serializable(d) No object is serializable

Answer» The correct choice is (b) If a class or any superclass implements java.io.Serializable interface

To explain I would say: A Java object is serializable if class or any its superclass implements java.io.Serializable or its subinterface java.io.Externalizable.
19.

Which of these is a method to clear all the data present in output buffers?(a) clear()(b) flush()(c) fflush()(d) close()

Answer» Right choice is (b) flush()

Easy explanation: None.
20.

Which of these is a method of ObjectOutput interface used to finalize the output state so that any buffers are cleared?(a) clear()(b) flush()(c) fflush()(d) close()

Answer» Right answer is (b) flush()

Easy explanation: None.
21.

Which of these package is used for remote method invocation?(a) java.applet(b) java.rmi(c) java.lang.rmi(d) java.lang.reflect

Answer» Right answer is (b) java.rmi

The best explanation: None.
22.

Which of these class allows us to get real time data about private and protected member of a class?(a) java.io(b) GetInformation(c) ReflectPermission(d) MembersPermission

Answer» Correct choice is (c) ReflectPermission

To elaborate: The ReflectPermission class allows reflection of private or protected members of a class. This was added after java 2.0 .
23.

Which of these method is used to start a server thread?(a) run()(b) start()(c) runThread()(d) startThread()

Answer» Right choice is (a) run()

To explain: run() method is called when the server thread is started.
24.

Which of these methods is used to know host of an URL?(a) host()(b) getHost()(c) GetHost()(d) gethost()

Answer» Correct option is (b) getHost()

The explanation: None.
25.

Which of these methods are member of Remote class?(a) checkIP()(b) addLocation()(c) AddServer()(d) None of the mentioned

Answer» Right choice is (d) None of the mentioned

The explanation is: Remote class does not define any methods, its purpose is simply to indicate that an interface uses remote methods.
26.

What does URL stands for?(a) Uniform Resource Locator(b) Uniform Resource Latch(c) Universal Resource Locator(d) Universal Resource Latch

Answer» Right answer is (a) Uniform Resource Locator

Explanation: URL is Uniform Resource Locator.
27.

Which of these Exceptions is thrown by remote method?(a) RemoteException(b) InputOutputException(c) RemoteAccessException(d) RemoteInputOutputException

Answer» The correct option is (a) RemoteException

Best explanation: All remote methods throw RemoteException.
28.

Which of these exceptions is thrown by URL class’s constructors?(a) URLNotFound(b) URLSourceNotFound(c) MalformedURLException(d) URLNotFoundException

Answer» Right choice is (c) MalformedURLException

Best explanation: None.
29.

Which of these is a super class of Character wrapper?(a) Long(b) Digits(c) Float(d) Number

Answer» Right choice is (d) Number

Explanation: Number is an abstract class containing subclasses Double, Float, Byte, Short, Character, Integer and Long.
30.

Where is String Pool stored?(a) Java Stack(b) Java Heap(c) Permanent Generation(d) Metaspace

Answer» Correct choice is (b) Java Heap

Easy explanation: When a string is created; if the string already exists in the pool, the reference of the existing string will be returned, else a new object is created and its reference is returned.
31.

What is not the use of “this” keyword in Java?(a) Passing itself to another method(b) Calling another constructor in constructor chaining(c) Referring to the instance variable when local variable has the same name(d) Passing itself to method of the same class

Answer» Right choice is (d) Passing itself to method of the same class

The best I can explain: “this” is an important keyword in java. It helps to distinguish between local variable and variables passed in the method as parameters.
32.

Which of the following has the highest memory requirement?(a) Heap(b) Stack(c) JVM(d) Class

Answer» Correct answer is (c) JVM

For explanation: JVM is the super set which contains heap, stack, objects, pointers, etc.
33.

Which of the following statements are incorrect?(a) static methods can call other static methods only(b) static methods must only access static data(c) static methods can not refer to this or super in any way(d) when object of class is declared, each object contains its own copy of static variables

Answer» Right choice is (d) when object of class is declared, each object contains its own copy of static variables

The explanation: All objects of class share same static variable, when object of a class are declared, all the objects share same copy of static members, no copy of static variables are made.
34.

Which of the following statements are incorrect?(a) Variables declared as final occupy memory(b) final variable must be initialized at the time of declaration(c) Arrays in java are implemented as an object(d) All arrays contain an attribute-length which contains the number of elements stored in the array

Answer» The correct choice is (a) Variables declared as final occupy memory

The best I can explain: None.
35.

Which of these Exception handlers cannot be type parameterized?(a) catch(b) throw(c) throws(d) all of the mentioned

Answer» Right choice is (d) all of the mentioned

The explanation is: we cannot Create, Catch, or Throw Objects of Parameterized Types as generic class cannot extend the Throwable class directly or indirectly.
36.

What would be the behaviour if one parameterized constructor is explicitly defined?(a) Compilation error(b) Compilation succeeds(c) Runtime error(d) Compilation succeeds but at the time of creating object using default constructor, it throws compilation error

Answer» The correct option is (d) Compilation succeeds but at the time of creating object using default constructor, it throws compilation error

Explanation: The class compiles successfully. But the object creation of that class gives a compilation error.
37.

Which of the following is an incorrect statement regarding the use of generics and parameterized types in Java?(a) Generics provide type safety by shifting more type checking responsibilities to the compiler(b) Generics and parameterized types eliminate the need for down casts when using Java Collections(c) When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes(d) All of the mentioned

Answer» Right choice is (c) When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes

The best explanation: None.
38.

Which of these statement is incorrect?(a) Every class must contain a main() method(b) Applets do not require a main() method at all(c) There can be only one main() method in a program(d) main() method must be made public

Answer» Right choice is (a) Every class must contain a main() method

To explain I would say: Every class does not need to have a main() method, there can be only one main() method which is made public.
39.

Which of these method of class String is used to extract a single character from a String object?(a) CHARAT()(b) chatat()(c) charAt()(d) ChatAt()

Answer» Correct choice is (c) charAt()

Easy explanation: None.
40.

Which of these method of class String is used to compare two String objects for their equality?(a) equals()(b) Equals()(c) isequal()(d) Isequal()

Answer» Correct option is (a) equals()

To explain: None.
41.

What is the process of defining more than one method in a class differentiated by method signature?(a) Function overriding(b) Function overloading(c) Function doubling(d) None of the mentioned

Answer» Correct choice is (b) Function overloading

Easy explanation: Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or parameters type and number. Example –  int volume(int length, int width) & int volume(int length , int width , int height) can be used to calculate volume.
42.

Which of the following is a method having same name as that of it’s class?(a) finalize(b) delete(c) class(d) constructor

Answer» The correct answer is (d) constructor

Best explanation: A constructor is a method that initializes an object immediately upon creation. It has the same name as that of class in which it resides.
43.

What is the return type of Constructors?(a) int(b) float(c) void(d) none of the mentioned

Answer» Right answer is (d) none of the mentioned

The explanation: Constructors does not have any return type, not even void.
44.

Which of these constructors is used to create an empty String object?(a) String()(b) String(void)(c) String(0)(d) None of the mentioned

Answer» Correct choice is (a) String()

To explain I would say: None.
45.

Which class loader loads jar files from JDK directory?(a) Bootstrap(b) Extension(c) System(d) Heap

Answer» The correct answer is (b) Extension

To explain: Extension loads jar files from lib/ext directory of the JRE. This gives the basic functionality available.
46.

Which of these methods initiates garbage collection?(a) gc()(b) garbage()(c) garbagecollection()(d) Systemgarbagecollection()

Answer» Right answer is (a) gc()

Explanation: None.
47.

Which of these method can set the out stream to OutputStream?(a) setStream()(b) setosteam()(c) setOut()(d) streamtoOstream()

Answer» Right option is (c) setOut()

To elaborate: None.
48.

Which of these methods loads the specified dynamic library?(a) load()(b) library()(c) loadlib()(d) loadlibrary()

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

The explanation is: load() methods loads the dynamic library whose name is specified.
49.

Which of the following is stored at client side?(a) URL rewriting(b) Hidden form fields(c) SSL sessions(d) Cookies

Answer» Correct answer is (d) Cookies

Explanation: Cookies are stored at client side. Hence, it is advantageous in some cases where clients disable cookies.
50.

Which of the below are common network protocols?(a) TCP(b) UDP(c) TCP and UDP(d) CNP

Answer» The correct choice is (c) TCP and UDP

To explain: Transmission Control Protocol(TCP) and User Datagram Protocol(UDP) are the two common network protocol. TCP/IP allows reliable communication between two applications. UDP is connection less protocol.