Java-Programming (Set 2)
Java-Programming (Set 2)
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
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
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
111. Which of these methods are used to register a keyboard event listener?
A. KeyListener()
B. addKistener()
C. addKeyListener()
D. eventKeyboardListener()
Answer:C
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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