0% found this document useful (0 votes)
27 views

Java-Programming (Set 2)

This document contains 150 multiple choice questions about Java programming topics including input/output, files, applets, events, layout managers, graphics, exceptions and inheritance.

Uploaded by

9649499308
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Java-Programming (Set 2)

This document contains 150 multiple choice questions about Java programming topics including input/output, files, applets, events, layout managers, graphics, exceptions and inheritance.

Uploaded by

9649499308
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Java Programming

2 of 7 sets

101. Java supports input/output of data through the classes included in the
_______ package: a) jav
A. oi
B. java.out
C. java.in
D. java.io
Answer:D

102. The ________ method help in clearing the contents of the buffer:
A. flush()
o m
B. clear()
. c
C. rub()
te
D. vanish()
a
Answer:A
q M
c
M
103. The _______ class is used to write bytes to a file:
A. FileInputStream
B. FileOutputStream
C. FileBufferStream
D. FileStringStream
Answer:B

104. The _______ class is used to read characters from the file:
A. StreamReader
B. CharacterReader
C. InputReader
D. FileReader
Answer:D

105. DataInputStream class contains methods to read________


A. Non primitive data type
B. Primitive data type
C. Formatted data
D. all of the above
Answer:B

106. Whenever the applet requires to redraw its output, it is done by using method
A. display()
B. paint()
C. displayApplet()
D. PrintApplet()
Answer:B

107. Which of these methods can be used to output a string in an applet?


A. display()
B. print()
C. drawString()
D. transient()
Answer:C

108. What does AWT stands for?


A. All Window Tools
B. All Writing Tools
C. Abstract Window Toolkit
D. Abstract Writing Toolkit
Answer:C

109. Which of these packages contains all the classes and methods required for
event handling in Java? a) jav
A. applet
B. java.awt
C. java.event
D. java.awt.event
Answer:D

110. What is an event in delegation event model used by Java programming


language?

View all MCQ's at McqMate.com


A. An event is an object that describes a state change in a source.
B. An event is an object that describes a state change in processing.
C. An event is an object that describes any change by the user and system.
D. An event is a class used for defining object, to create events.
Answer:A

111. Which of these methods are used to register a keyboard event listener?
A. KeyListener()
B. addKistener()
C. addKeyListener()
D. eventKeyboardListener()
Answer:C

112. Which of these methods are used to register a MouseMotionListener?


A. addMouse()
B. addMouseListener()
C. addMouseMotionListner()
D. eventMouseMotionListener()
Answer:C

113. What is a listener in context to event handling?


A. A listener is a variable that is notified when an event occurs.
B. A listener is an interface that is notified when an event occurs.
C. A listener is a method that is notified when an event occurs.
D. None of the mentioned
Answer:B

114. Which of these class is super class of all AWT events?


A. AWTEvent
B. EventClass
C. ActionEvent
D. ItemEvent
Answer:A

115. Which of these events will be generated if scroll bar is manipulated?

View all MCQ's at McqMate.com


A. ActionEvent
B. ComponentEvent
C. AdjustmentEvent
D. WindowEvent
Answer:C

116. Which of these events will be generated if we close a Frame window?


A. ActionEvent
B. ComponentEvent
C. AdjustmentEvent
D. WindowEvent
Answer:D

117. Which of these events is generated when a button is pressed?


A. ActionEvent
B. KeyEvent
C. WindowEvent
D. AdjustmentEvent
Answer:A

118. Which of these methods can be used to obtain the command name for
ActionEvent object?
A. getCommand()
B. getActionCommand()
C. getActionEvent()
D. getActionEventCommand()
Answer:B

119. Which of these methods in KeyEvent class can be used to know which key is
pressed?
A. getKeyCode()
B. getModifier()
C. getActionKey()
D. getActionEvent()
Answer:A

View all MCQ's at McqMate.com


120. Which of these interfaces define a method actionPerformed()?
A. ComponentListener
B. ContainerListener
C. ActionListener
D. InputListener
Answer:C

121. Which of these interfaces define a method itemStateChanged()?


A. ComponentListener
B. ContainerListener
C. ActionListener
D. ItemListener
Answer:D

122. What are the sequences of method executed when an Applet starts execution?
A. init(),start(),stop(),destroy()
B. load(),start(),stop(),unload()
C. init(),activate(),deactivate(),destroy()
D. start(),init(),destroy(),stop()
Answer:A

123. The default layout manager of an Applet is


A. Flowlayout
B. Gridlayout
C. BorderLayout
D. BoxLayout
Answer:A

124. The default layout manager of a Frame is


A. Flowlayout
B. Gridlayout
C. BorderLayout
D. BoxLayout
Answer:C

View all MCQ's at McqMate.com


125. Which package consist an applet class? a) jav
A. applet
B. java.awt
C. java.awt.applet
D. java.event
Answer:A

126. How do you position a component using FlowLayout?


A. North, South, East, West
B. Assign a row/column grid reference
C. Pass a X/Y percentage parameter to the add method
D. Do nothing, the FlowLayout will position the component
Answer:D

127. How do you change the current layout manager for a container
A. Use the setLayout() method
B. Once created you cannot change the current layout manager of a component
C. Use the setLayoutManager() method
D. Use the updateLayout() method
Answer:A

128. The AWT component used to display a single line of read-only text
A. A checkbox
B. A Label
C. A button
D. A TextField
Answer:B

129. The method to get the text of a Label


A. getLabel()
B. getText()
C. getString()
D. getData()
Answer:B

View all MCQ's at McqMate.com


130. The AWT component used for taking input from user.
A. A TextBox
B. A Label
C. A button
D. A TextField
Answer:D

131. The method to set the text of Textfield.


A. setLabel()
B. setString()
C. setText()
D. setData()
Answer:C

132. The class used to create a Radio button in awt is


A. Checkbox
B. RadioButton
C. OptionButton
D. CheckboxGroup
Answer:D

133. A ------------ is an object that the user can see on the screen and-in most cases-
interact with.
A. an Event
B. a window
C. a Component
D. a Listener
Answer:C

134. A ------------- is a component that can hold other components.


A. A window
B. a container
C. A control
D. a form
Answer:B

View all MCQ's at McqMate.com


135. The method that returns the selected item from a List component is
A. getSelected()
B. getSelectedString()
C. getSelectedItem()
D. getSelectedData()
Answer:C

136. The class used to make a standalone application in java.


A. Applet
B. Panel
C. Frame
D. Form
Answer:C

137. ------------------- is an example of container class


A. Label
B. Panel
C. TextField
D. Button
Answer:B

138. The class used to encapsulate fonts is


A. Graphics
B. Font
C. Applet
D. Component
Answer:B

139. The method used to set Fonts is


A. setFontName()
B. setFont()
C. setFontText()
D. none of these
Answer:B

View all MCQ's at McqMate.com


140. The method setFont() is defined in---------- class
A. Applet
B. Font
C. Container
D. Component
Answer:D

141. The layout manager that lets you align components at north, south, east, west
directions is
A. BorderLayout
B. GridLayout
C. FlowLayout
D. GridBagLayout
Answer:A

142. The layout manager that lays out a container's components in a rectangular
grid.
A. BorderLayout
B. GridLayout
C. FlowLayout
D. GridBagLayout
Answer:B

143. The class used for drawing graphics in an application is


A. Canvas
B. Graphics
C. Layer
D. Container
Answer:B

144. The method in Graphics class to draw a circle/oval with specified width and
height.
A. drawCircle()
B. drawShape()
C. drawOval()
D. none of these

View all MCQ's at McqMate.com


Answer:C

145. The method in Graphics class to set the drawing color


A. setForeground()
B. setDrawingColor()
C. setBrushColor()
D. setColor()
Answer:D

146. The method used to draw an ellipse is


A. drawEllipse()
B. drawCircle()
C. drawOval()
D. none of these
Answer:C

147. Which of the following statements is legal in Java? (i) mysRef = (Mystery)
mySecret; (ii) mysRef = (Mystery) secRef;
A. Only (i)
B. Only (ii)
C. Both (i) and (ii)
D. None of these
Answer:B

148. In a ____ control structure, the computer executes particular statements


depending on some condition(s).
A. looping
B. repetition
C. selection
D. sequence
Answer:C

149. What is the value of y if x = 2?


A. 2
B. 3
C. 7

View all MCQ's at McqMate.com


D. 9
Answer:D

150. Two-way selection in Java is implemented using ________.


A. if statements
B. for loops
C. if...else statements
D. sequential statements
Answer:C

151. Which of the following will cause a semantic error, if you are trying to
compare x to 5?
A. if (x == 5)
B. if (x = 5)
C. if (x <= 5)
D. if (x >= 5)
Answer:B

152. How many constructors does the class Exception have?


A. 0
B. 1
C. 2
D. 3
Answer:C

153. If class Dog has a subclass Retriever, which of the following is true?
A. Because of single inheritance, Dog can have no other subclasses.
B. Because of single inheritance, Retriever can extend no other class except Dog.
C. The relationship between these classes implies that Dog “is-a” Retriever.
D. The relationship between these classes implies that Retriever “has-a” Dog.
Answer:B

154. If there are three classes: Shape, Circle, and Square, what is the most likely
relationship between them?
A. Square is a superclass, and Shape and Circle are subclasses of Square.
B. Shape is a superclass, and Circle and Square are subclasses of Shape.

View all MCQ's at McqMate.com


C. Shape, Circle, and Square are all sibling classes.
D. These three classes cannot be related.
Answer:B

155. What is byte code in the context of Java?


A. The type of code generated by a Java compiler
B. The type of code generated by a Java Virtual Machine
C. It is another name for a Java source file
D. It is the code written within the instance methods of a class.
Answer:A

156. What is garbage collection in the context of Java?


A. The operating system periodically deletes all of the java files available on the system.
B. Any package imported in a program and not used is automatically deleted.
C. When all references to an object are gone, the memory used by the object is automatically
reclaim
Answer:C

157. What is different between a Java applet and a Java application?


A. An application can in general be trusted whereas an applet can't.
B. An applet must be executed in a browser environment.
C. An applet is not able to access the files of the computer it runs on
D. All of the above
Answer:D

158. JAR stands for?


A. Java Archive
B. Java Archive Runner
C. Java Application Runner
D. None of the above
Answer:A

159. What are the pillars of OOPS concept?


A. Abstraction, Inheritance, Encapsulation, Polymorphism
B. Atomicity, Inheritance, Encapsulation, Polymorphism

View all MCQ's at McqMate.com


C. Abstraction, Inheritance, Polymorphism
D. None of the Above
Answer:A

160. What is the default buffer size used by any buffered class?
A. 128 bytes
B. 256 bytes
C. 512 bytes
D. 1024 bytes
Answer:C

161. Which class cannot be a subclass in java


A. Abstract class
B. Parent class
C. Final class
D. None of above
Answer:C

162. Why we use array as a parameter of main method


A. It is syntax
B. Can store multiple values
C. Both of above
D. None of above
Answer:B

163. What is 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:A

164. Which of these can be overloaded?


A. Methods
B. Constructors

View all MCQ's at McqMate.com


C. Both a & b
D. None of the mentioned
Answer:C

165. 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:A

166. What is the process of defining a method in terms of itself that is a method
that calls itself?
A. Polymorphism
B. Abstraction
C. Encapsulation
D. Recursion
Answer:D

167. Which of the following statements are incorrect?


A. Default constructor is called at the time of declaration of the object if a constructor has not
been defined.
B. Constructor can be parameterized.
C. Finalize() method is called when a object goes out of scope and is no longer need
Answer:C

168. What is the stored in the object obj in following lines of code? box obj;
A. Memory address of allocated memory of object.
B. NULL
C. Any arbitrary pointer
D. Garbage
Answer:B

169. Which of the following is a valid declaration of an object of class Box?

View all MCQ's at McqMate.com


A. Box obj = new Box();
B. Box obj = new Box;
C. obj = new Box();
D. new Box obj;
Answer:A

170. Which of this 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:A

171. Which of the following statements is correct?


A. Public method is accessible to all other classes in the hierarchy
B. Public method is accessible only to subclasses of its parent class
C. Public method can only be called by object of its class.
D. Public method can be accessed by calling object of the public class.
Answer:A

172. Program which executes applet is known as


A. applet engine
B. virtual machine
C. JVM
D. None of above
Answer:A

173. You read the following statement in a Java program that compiles and
executes. submarine.dive(depth); What can you say for sure?
A. Depth must be an int
B. Dive must be a method.
C. Dive must be the name of an instance fie
Answer:B

174. Which is true about an anonymous inner class?


A. It can extend exactly one class and implement exactly one interface.

View all MCQ's at McqMate.com


B. It can extend exactly one class and can implement multiple interfaces.
C. It can implement multiple interfaces regardless of whether it also extends a class.
D. none
Answer:B

175. If a thread is to be declared as a daemon thread, it must be declared before


A. start method
B. run method
C. stop method
D. none
Answer:A

176. Under what circumstances might you use the yield method of the Thread class
A. To call from the currently running thread to allow another thread of the same or higher priority
to run
B. To call on a waiting thread to allow it to run
C. To allow a thread of higher priority to run
D. To call from the currently running thread with a parameter designating which thread should be
allowed to run
Answer:A

177. Which of the following is the correct syntax for suggesting that the JVM
performs garbage collection?
A. System.free();
B. System.setGarbageCollection();
C. System.out.gc();
D. System.gc();
Answer:D

178. A class that cannot be a subclass is called as______ class.


A. abstract
B. parent class
C. Final
D. none of these
Answer:C

View all MCQ's at McqMate.com


179. When method defined in subclass which has same signature as a method in a
super class, it is known as method
A. Overloading
B. Overriding
C. Packing
D. None of these
Answer:B

180. Which of the following statement is correct?


A. For positive numbers, result of operators >> and >>> are same
B. Java provides two operators to do left shift <<< and <<
C. >> is the zero fill right shift operator
D. >>> is the signed right shift operator
Answer:A

181. Java language has support for which of the following types of comment ?
A. block, line and javadoc
B. javadoc, literal and string
C. javadoc, char and string
D. single, multiple and quote
Answer:A

182. Consider the following program: import myLibrary.*; public class


ShowSomeClass { // code for the class... } What is the name of the java file
containing this program?
A. myLibrary.java
B. ShowSomeClass.java
C. ShowSomeClass
D. ShowSomeClass.class 1.
Answer:B

183. Which of the following is TRUE?


A. In java, an instance field declared public generates a compilation error.
B. int is the name of a class available in the package java.lang
C. Instance variable names may only contain letters and digits.
D. A class has always a constructor (possibly automatically supplied by the java compiler).

View all MCQ's at McqMate.com


Answer:D

184. Consider the following code snippet String river = new String(“Columbia”);
System.out.println(river.length()); What is printed?
A. 6
B. 7
C. 8
D. Columbia
Answer:C

185. What is different between a Java applet and a Java application?


A. An application can in general be trusted whereas an applet can't.
B. An applet must be executed in a browser environment.
C. An applet is not able to access the files of the computer it runs on
D. (A), (B) and (C).
Answer:D

186. You read the following statement in a Java program that compiles and
executes. submarine.dive(depth); What can you say for sure?
A. depth must be an int
B. dive must be a method.
C. dive must be the name of an instance fie
Answer:B

187. Consider public class MyClass{ public MyClass(){/*code*/} // more code... }


To instantiate MyClass, you would write?
A. MyClass mc = new MyClass();
B. MyClass mc = MyClass();
C. MyClass mc = MyClass;
D. MyClass mc = new MyClass; 7. E. It can't be done. The constructor of MyClass should be
defined as public void MyClass(){/*code*/}
Answer:A

188. In Java Inheritance


A. all fields of a class are private
B. all fields of a class are protected

View all MCQ's at McqMate.com


C. a new class is derived from an existing class
D. none of these above
Answer:C

189. What happens in a method if there is an exception thrown in a try block but
there is no catch block following the try block?
A. The program ignores the exception.
B. The program will not compile without a complete try/catch structure.
C. The program terminates immediately.
D. The program throws an exception and proceeds to execute the finally block.
Answer:D

190. The class RuntimeException is the superclass of which of the following


classes?
A. NullPointerException
B. NoSuchMethodException
C. IllegalAccessException
D. NoSuchFileException
Answer:A

191. How many finally blocks can there be in a try/catch structure?


A. There must be 1.
B. There can be 1 following each catch block.
C. There can be 0 or 1 following the last catch block.
D. There is no limit to the number of finally blocks following the last catch block.
Answer:C

192. Which of the following statements is NOT true about creating your own
exceptions?
A. Typically, constructors are the only methods that you include when you define your own
exception class.
B. The exception class that you define extends either the class Throwable or one of its
subclasses.
C. If you have created an exception class, you can define other exception classes extending the
definition of the exception class you creat
Answer:B

View all MCQ's at McqMate.com


193. What can a method do with a checked exception?
A. Check the exception or ignore it.
B. Return the exception to the sender or handle it in a catch block.
C. Throw the exception to the method that called this method, or handle the exception in a catch
block.
D. Handle the exception in the try block or handle the exception in the catch block.
Answer:C

194. Which of the following is an exception thrown by the methods of the class
String?
A. NullPointerException
B. FileNotFoundException
C. NoSuchElementsException
D. NumberFormatException
Answer:A

195. Which of the following statements is true?


A. The class Exception, which is derived from the class Object, is the superclass of the class
Throwable.
B. The class Throwable, which is derived from the class Exception, is the superclass of the class
Object.
C. The class Throwable, which is derived from the class Object, is the superclass of the class
Exception.
D. None of these
Answer:C

196. A message string is returned by which method of an Exception object?


A. printMessage()
B. getMessage()
C. printStackTrace()
D. traceMessage()
Answer:B

197. When is a finally {} block executed?


A. Only when an exception is thrown by a try block
B. Only when there are no exceptions thrown

View all MCQ's at McqMate.com


C. At the end of a program
D. Always after the execution of a try block, regardless of whether or not an exception is thrown
Answer:D

198. When does Exceptions in Java arises in code sequence?


A. Run Time
B. Compilation Time
C. Can Occur Any Time
D. None of the mentioned
Answer:A

199. Which of these keywords is not a part of exception handling?


A. try
B. finally
C. thrown
D. catch
Answer:C

200. Which of these keywords is used to manually throw an exception?


A. try
B. finally
C. throw
D. catch
Answer:C

View all MCQ's at McqMate.com

You might also like