MCQ's Based on Java
MCQ's Based on Java
MCQ's Based on Java
1. Which of these components are used in a Java program for compilation, debugging,
and execution?
a. JDK
b. JVM
i
c. JRE
in
d. JIT
a. -3.4e+050
b. +1.7e+308
l
hi
c. -3.4e+038
d. -1.7e+308
ik
3. What is BigDecimal.ONE?
N
a. it is a custom-defined statement
b. it is a wrong statement
4. When an expression consists of int, double, long, float, then the entire expression will
get promoted into a data type that is:
a. float
b. double
c. int
i
d. long
in
Answer: (b) double
A. &&
Sa
B. ==
C. ?:
l
hi
D. +=
a) C & B
ik
b) A & D
c) A, B & D
N
d) A, B & C
c. The addition operator + and the subtraction operator – have an equal precedence
Answer: (d) The division operator / has comparatively higher precedence as compared
to a multiplication operator
i
in
class Output
{
Sa
public static void main(String args[])
int p = 1;
l
int q = 2;
hi
int r = 3;
p |= 4;
ik
q >>= 1;
N
r <<= 1;
p ^= r;
System.out.println(q + ” ” + q + ” ” + r);
}
a. 3 3 6
b. 2 3 4
c. 2 2 3
d. 3 1 6
Answer: (d) 3 1 6
i
in
class P
a) Compilation Error
ik
b) Runtime Error
N
c) EnumNotDefined Exception
d) It runs successfully
b. When more than a single method have the same name, the same signature, but have
different numbers of signature
c. When more than a single method have the same signature, same name, and the
same number of parameters have different types
d. When more than a single method have the same name, the same number and types
i
of parameters, and yet different signatures
in
Answer: (d) When more than a single method have the same name, the same number
and types of parameters, and yet different signatures
Sa
10. What is it called when the child object also gets killed when the parent object is
killed in the program?
a. Encapsulation
b. Association
l
hi
c. Aggregation
d. Composition
ik
11. How does one identify if a compilation unit is an interface or class from a .class file?
N
12. Out of these methods of the String class, which one can be used for testing the
strings for equality?
a. isequals()
b. isequal()
c. equals()
i
d. equal()
in
Answer: (c) equals()
13. What would happen to the thread whenever the garbage collection kicks off?
Sa
a. The garbage collection won’t happen until the running of the thread
c. The garbage collection and the thread don’t interfere with each other
l
hi
d. The thread would be paused while the running of the garbage collection
Answer: (d) The thread would be paused while the running of the garbage collection
ik
14. Out of these, which one is the correct way of calling a constructor that has no
parameters of the superclass A by the subclass B?
N
a. superclass.();
b. super(void);
c. super();
d. super.A();
a. Object clone()
b. clone()
c. Object copy()
d. copy()
i
in
16. Out of these packages, which one contains an abstract keyword?
a. java.util
b. java.lang
c. java.system
Sa
d. java.io
17. Out of these methods, which one can be used for converting all the characters
present in a String into an Array of characters?
ik
d. charAt()
18. What value is returned by the compareTo() function in case the invoking string
happens to be greater than the compared string?
a. a value that is greater than zero
c. zero
19. Out of these exceptions, which one is thrown by the compareTo() method that is
i
defined in a double wrapper?
in
a. SystemException
b. ClassCastException
c. IOException
Sa
d. CastException
a. Metaspace
ik
b. Java Stack
c. Java Heap
N
d. Permanent Generation
21. Out of these data members of the HttpResponse class, which one is used for the
storage of the response that is from an http server?
a. address
b. status
c. statusCode
d. statusResponse
22. Out of these methods, which one makes the raw MIME formatted string?
a. toString()
i
in
b. getString()
c. parse()
d. parseString()
a. ObjectNotFoundException
l
hi
b. IllegalStateException
c. IOException
ik
d. SystemException
N
24. Out of the following, which one is a superclass of all the exception type classes?
a. String
b. RuntimeExceptions
c. Catchable
d. Throwable
25. What happens when we call two threads that have the same priority to process
simultaneously?
i
c. Itdepends on the OS
in
d. There will be no execution of threads
a. StringReader
l
b. BufferedReader
hi
c. InputStreamReader
d. BufferedStreamReader
ik
27. Out of these operators, which one can be used to get the run time info about an
object?
a. Info
b. getInfo
c. getinfoof
d. instanceof
28. Out of these classes, which one allows a user to define their own formatting pattern
for time and dates?
a. UsersDateFormat
b. ComplexDateFormat
i
c. SimpleDateFormat
in
d. DefinedDateFormat
a. transient()
b. drawString()
l
hi
c. print()
d. display()
ik
31. Which one is a superclass of the ContainerEvent class out of the following?
a. ComponentEvent
b. InputEvent
c. ItemEvent
d. WindowEvent
i
in
Answer: (a) ComponentEvent
a. ComponentEvent
b. Applet
Sa
c. InputEvent
d. Event
l
hi
a. randomBoolean()
N
b. nextBoolean()
c. generateBoolean()
d. previousBoolean()
34. Which class produces objects with respect to their geographical locations?
a. Simple TimeZone
b. Date
c. Locale
d. TimeZone
35. Which method is used for notifying the observer about the change in the observed
i
object?
in
a. notify()
b. update()
c. observed()
Sa
d. check()
a. java.awt
ik
b. java.rmi
c. java.applet
N
d. java.util
c. The generics add stability to a code. They do so by making more bugs detectable at
the runtime
d. The generics add stability to a code. They do so by making more bugs detectable at
the compile time
Answer: (d) The generics add stability to a code. They do so by making more bugs
detectable at the compile time
i
38. Which mechanism helps in the process of naming as well as visibility control of the
in
classes and their content?
a. Packages
b. Interfaces
Sa
c. Object
a. .sql
b. .ora
N
c. .hbm
d. .dbm
b. reads the files that are at the path specified as the String
c. counts the total number of lines for the files at the specified path
Answer: (a) reads the lines that are from a file as the Stream
i
in
a. bound
b. stop
c. implements
d. extends
Sa
Answer: (d) extends
42. Out of the following statements, which one is not true about the Java beans?
l
hi
i
in
c. Encourages SQL injection
d. Slow performance
Sa
Answer: (b) Prevents SQL injection
45. How does one move from some desired step to another one?
a. logger.error
b. logger.log
l
hi
c. System.out.println
d. breakpoints
ik
46. What would happen if the IP Address of the host can’t be determined?
a) IOException is thrown
d) UnknownHostException is thrown
Answer: (d) UnknownHostException is thrown
a) 4095 MegaBytes
b) 4095 bytes
c) 2048 bytes
d) 2048 MegaBytes
i
in
Answer: (b) 4095 bytes
a) jsp:plugin
b) jsp:include
Sa
c) jsp:getProperty
d) jsp:setProperty
l
hi
a) dependency.xml
N
b) build.xml
c) version.xml
d) pom.xml
i
in
Thanks & Regards
Sa
Nikhil Saini
Technical Trainer IMSEC
l
hi
ik
N