Part - 2 - OOP Sample Questions
Part - 2 - OOP Sample Questions
Part-2
Q. Which of these packages contain classes and interfaces used for input & output operations of a
program?
A. javA.util
B. javA.lang
C. javA.io
Answer: C
A. String
B. Reader
C. Writer
D. File
Answer: A
Q. Which of these classes is used for input and output operation when working with bytes?
A. InputStream
B. Reader
C. Writer
Answer: A
A. FileReader
B. FileWriter
C. FileInputStream
D. InputStreamReader
Answer: A
Answer: A
Q. Which class is used to create servers that listen for either local client or remote client programs?
A. ServerSockets
B. httpServer
C. httpResponse
Answer: A
A. javA.io
B. javA.util
C. javA.net
D. javA.network
Answer: C
A. 10
B. 1024
C. 2048
D. 512
Answer: B
Q. What are the 2 possible way to create thread in Java?
D. none of these
Answer: A
A. start method
B. run method
C. create method
D. main method
Answer: B
A. getThreadName()
B. getName()
C. displayThreadName()
D. currentThreadName()
Answer: B
A. 1
B. 5
C. 10
D. 8
Answer: C
Q. In java multi-threading, a thread can be created by
C. Using both
D. None of these
Answer: C
A. 10
B. 12
C. 5
D. 8
Answer: A
A. parameterized types
B. class
C. structure
D. interface
Answer: A
Answer: D
Q. Which of these type parameters is used for a generic methods to return and accept any type of
object?
A. K
B. N
C. T
D. V
Answer: C
Q. Which of these type parameters is used for a generic methods to return and accept a number?
A. K
B. N
C. T
D. V
Answer: B
A. AWT
B. Applets
C. Swing
D. Swift
Answer: C
Answer: D
Q. Which of these classes are used by character streams for input and output operations?
A. InputStream
B. Writer
C. ReadStream
D. InputOutputStream
Answer: B
Q. Which of these classes defined in javA.io and used for file-handling are abstract?
1. InputStream
2. PrintStream
3. Reader
4. FileInputStream
A. Only 1
B. Only 3
C. 1 and 3
D. 2 and 4
Answer: C
A. FileInputStream
B. FileOutputStream
C. Both A & B
Answer: B
Q. Which is used for reading streams of raw bytes such as image datA. For reading streams of
characters, consider using FileReader?
A. FileInputStream
B. FileOutputStream
C. Both A & B
Answer: A
A. InputStreamReader
B. Console
C. Scanner
Answer: D
Q. Which class can be used to read data line by line by readLine() method?
A. BufferedReader
B. InputStreamReader
C. DataInputStream
Answer: A
A. 4
B. 5
C. 3
D. 2
Answer: B
Q. Which method is used in thread class to starts the execution of the threaD.JVM calls the run() method
on the thread?
Answer: A
A. Yes
B. No
Answer: B
A. stop()
B. start()
C. terminate()
D. join()
Answer: D
A. currentThread()
B. runningThread()
C. runnableThread()
Answer: A
Answer: B
Q. Default priority value of a thread class for NORM_PRIORITY is?
A. 1
B. 10
C. 5
D. 4
Answer: C
Q. Daemon thread provides services to user threads for background supporting tasks,It has no role in life
than to serve user threads?
A. True
B. False
Answer: A
Q. If you want to make a user thread as Daemon, it must not be started otherwise it will throw
IllegalThreadStateException?
A. True
B. False
Answer: A
A. Overloaded Methods
B. Generic methods
C. Class methods
D. Overriding methods
Answer: A
m.set("merit");
System.out.println(m.get());
class MyGen<T>
T var;
this.var = var;
T get()
return var;
A. merit
B. 0
C. Compilation Error
D. Runtime Error
Answer: B
interface A {
int count();
void show();
T process(T t) {
t.count();
t.show();
return t;
class C implements A {
A. LINE A
B. LINE B
C. LINE C
D. LINE D
Answer: B
{
GenericsWithObjects<int> integerObject = new GenericsWithObjects<int>(12);
integerObject.print();
class GenericsWithObjects<T>
T obj;
GenericsWithObjects(T obj)
this.obj = obj;
void print()
System.out.println(obj);
A. 12
C. Compilation Error
D. Runtime Error
Answer: C
C. Generics add stability to your code by making more of your bugs detectable at compile time.
D. Generics add stability to your code by making more of your bugs detectable at run time.
Answer: C
Q. What will be the output of the following program?
import java.util.*;
obj.push(36);
System.out.println(obj.pop());
class Sample<E>
ob.push(obj);
public E pop() {
E obj = ob.pop();
return obj;
A. 36
C. Compilation Error
D. Runtime Error
Answer: A
a) Process based
b) Thread based
c) Process and Thread based
Answer: C
a) Integer
b) Float
c) double
d) long
Answer: A
Q. What will happen if two thread of the same priority are called to be processed simultaneously?
Answer: D
a) By multithreading CPU idle time is minimized, and we can take maximum use of it
b) By multitasking CPU idle time is minimized, and we can take maximum use of it
Answer: D
class multithreaded_programing
Thread t = Thread.currentThread();
System.out.println(t);
a) Thread[5,main]
b) Thread[main,5]
c) Thread[main,0]
d) Thread[main,5,main]
Answer: D
class multithreaded_programing
Thread t = Thread.currentThread();
System.out.println(t);
a) 4
b) 5
c) 0
d) 1
Answer: B
Thread t = Thread.currentThread();
System.out.println(t);
a) main
b) Thread
c) System
Answer: A
A. 10
B. 12
C. 5
D. 8
Answer: A
A. run()
B. execute()
C. start()
D. None
Answer: A
threadE.start();
Answer: C
A. isAlive()
B. run ()
C. alive ()
D keepAlive()
Answer: A
A. 1, 10
B. 0,10
C. 0,255
D. 1,256
Answer: A
A. run ()
B. start ()
C. execute ()
D. call ()
Answer: A
A. Background
B. Foreground
C. Both
D. none
Answer: A
A. setDaemon(boolean value)
B. setThread(boolean value)
C. createDaemon(boolean value)
D. makeDeamon(boolean value);
Answer : A
Answer: A
A. start()
B. run()
C. Main()
D. execute()
Answer: B
D. All
Answer: D
A. runningThread()
B. currentThread()
C. runnableThread()
D. None
Answer: B
Answer: B
Q. Which is the container that contain title bar and can have MenuBars. It can have other components
like button, textfield etc.?
A. Panel
B. Frame
C. Window
D. Container
Answer: B
Q. Which is a component in AWT that can contain another components like buttons, textfields, labels
etc.?
A. Window
B. Container
C. Panel
D. Frame
Answer: B
A. True
B. False
Answer: A
A. java.awt
B. java.Graphics
C. java.awt.Graphics
D. None of the above
Answer: C
Q.These two ways are used to create a Frame By creating the object of Frame class (association) By
extending Frame class (inheritance)
A. True
B. False
Answer: A
Q. Which is the container that doesn't contain title bar and MenuBars. It can have other components
A. Window
B. Frame
C. Panel
D. Container
Answer: C
Q. How many types of controls does AWT supports these controls are subclasses of component?
A. 7
B. 6
C. 5
D. 8
Answer: A
A. Choice
B. List
C. Labels
D. Checkbox
Answer: C
A. setText()
B. getText()
C. Both A & B
Answer: A
A. List
B. Choice
C. Labels
D. Checkbox
Answer: B
A. Labels
B. Choice
C. List
D. Checkbox
Answer: C
B. Panel
C. Frame
D. Container
Answer: C
Q. The following way is used to create a frame is by creating the object of Frame class?
A. inheritance
B. association
C. Both A & B
Answer: B
Q. AWT more powerful components like tables, lists,scroll panes, color chooser, tabbed pane etc.?
A. True
B. False
Answer: A
A. Graphics class
B. Component class
C. Both A & B
Answer: B
Q. In Graphics class which method is used to draws a rectangle with the specified width and height?
C. public abstract void drawLine(int x1, int y1, int x2, int y2)
Answer: B
Q. Implement the Listener interface and overrides its methods is required to perform in event handling?
A. True
B. False
Answer: A
A. MenuComponent
B. MenuContainer
C. ComponentMenu
D. MenuBar
Answer: A
Answer: C
B. A Panel is a window that does not contain titlebar, menubar and border.
C. Panel is a superclass of Applet.
Answer: D
Q. What is API?
D. None of these
Answer: C
A. FlowLayout
B. GridLayout
C. CardLayout
D. BorderLayout
Answer: A
A. getItem( )
B. getSelectedItem( )
C. getItemCount( )
D. getCount( )
Answer: C
Answer: C
A. GridLayout(int a)
D. GridLayout(int hor)
Answer: B
A. Modal DialogBox
C. Modam
Answer: B
ScrollBar s = new
ScrollBar(0,10,20,0,1000);
A. size of thumb
B. minimum value
C. Increment value
D. Initial Value
Answer: A
Q. Which class is used to represent a single line textbox with password character facility?
A. TextField
B. TextArea
C. Label
D. Checkbox
Answer: A
Answer: A
Q. Suppose a Panel is added to a Frame and a Button is added to the Panel. If the Frame’s font is set to
12 point Times New Roman, the panel’s font is set 10 points Times New Roman and the Button’s font is
not set. What font will be used to display the Button’s label?
Answer: C
A. FlowLayout can use multiple rows if the horizontal space in the container is too small to hold the
component.
D. Both A & B.
Answer: D
A. display( )
B. print( )
C. drawString( )
D. transient( )
Answer: C
Q. ___________ positions are the components into 5 regions east, west, south, north, center.
A. CardLayout
B. BorderLayout
C. GridLayout
D. FlowLayout
Answer: B
B. A Panel is a window that does not contain a title bar, menu bar or border
D. All of above
Answer: D
A. List
B. Choice
C. Panel
D. TextArea
Answer: A
Q. When there is a switching condition like ON or OFF, which control is used of following?
A. Button
B. RadioButton
C. ToggleButton
D. TextField
Answer: C
A. setPasswordCharacter( )
B. setEchoChar( )
C. setPassChar( )
D. setEchoCharacter( )
Answer: B
A. JApplet
B. JFrame
C. JButton
D. None of these
Answer: D
A. Frame
B. Applet
C. Component
D. Panel
Answer: C
A. TextField
B. JTextField
C. EditTextField
D. TextArea
Answer: B
Q. Which Text Component method is used to set a TextComponent to the read‐only state?
A. Editable
B. NonEditable
C. setEchoChar
D. setEditable
Answer: D
Q. How would you set the color of graphics context called g to cyan?
A. g.setColor(“cyan”);
B. g.setCurrentColor(cyan);
C. g.setColor(“Color.cyan”);
D. g.setColor(Color.cyan);
Answer: D
Answer: C
Q. The setBackground() method is part of which of the following class java.awt package?
A. Component
B. Applet
C. Object
D. Graphics
Answer: A
Q. What does the following line of code do? TextField tf = new TextField(10);
C. Both A & B
D. None of These
Answer: B
Q. Frame is a standard window, which is __________ of Window class from AWT hierarchy?
C. Root class
D. Family class
Answer: A
A. Button
B. RadioButton
C. Choice
D. Label
Answer: D
A. FlowLayout
B. BorderLayout
C. GridLayout
D. CardLayout
Answer: C
Q. Which method is used to check the status of checkbox?
A. getStatus( )
B. getState( )
C. isChecked( )
D. getChecked( )
Answer: B
A. Editable( )
B. nonEditable( )
C. setEchoChar( )
D. setEditable( )
Answer: D
A. List
B. Checkbox
C. MenuItem
D. TextField
Answer: C
Q. Which of the following does not have its default layout as BorderLayout.
A. Frame
B. Dialog
C. JApplet
D. All of Above
Answer: D
Q. Which of the following statement about GUI component is wrong?
Answer: C
A. java.applet
B. java.awt
C. java.awt.image
D. java.io
Answer: B
D. None of these
Answer: C
A. Button
B. TextField
C. FlowLayout
D. Label
Answer: B
B. getAlignment( )
C. getText( )
D. setText( )
Answer: C
A. mb.addMenuItem(m)
B. mb.addItem(m)
C. mb.add(m)
D. None of these
Answer: C
A. Label
B. Button
C. CheckboxGroup
D. All of above
Answer: C
Answer: C
Q. Which of these classes can be added to any Container class, using the add method defined in
Container class?
A. Button
B. CheckboxMenuItem
C. Menu
D. MenuBar
Answer: A
C. Both A & B
Answer: C
item in choice.
A. getSelectedItem( )
B. getSelectedElement( )
C. getSelectedIndex( )
D. getItem( )
Answer: A
A. GridLayout
B. CardLayout
C. FlowLayout
D. BorderLayout
Answer: C
B. user interactive
C. Both A & B
D. None of these
Answer: C
Q. The Following steps are required to perform Implement the Listener interface and overrides its
methods Register the component with the Listener
A. Exception Handling
B. String Handling
C. Event Handling
Answer: C
A. Same class
B. Other class
C. Annonymous class
Answer: D
Q. Which package provides many event classes and Listener interfaces for event handling?
A. java.awt
B. java.awt.Graphics
C. java.awt.event
Answer: C
Q. To use the ActionListener interface it must be implemented by a class there are several ways to do
that find in the following?
Answer: D
A. True
B. False
Answer: B
Q. The ActionListener interface is used for handling action events, For example, it's used by a
A. JButton
B. JCheckbox
C. All of these
D. JMenuItem
Answer: C
A. Button,List,MenuItem
B. Button,Checkbox,Choice
C. Scrollbar,Component,Button
Answer: A
Q. In Graphics class Which method is used to set the graphics current color to the specified color?
Answer: B
Q. Which of the following method is used to determine the type of adjustment event?
A. getType( )
B. getEventType( )
C. getAdjustmentType( )
D. getEventObjectType( )
Answer: C
A. ActionEvent,ItemEvent
B. ActionEvent, TextEvent
C. ScrollEvent,TextEvent
D. ActionEvent, ScrollEvent
Answer: B
B. pressed
C. released
Answer: A
A. KeyEvent
B. MouseEvent
C. ItemEvent
D. AdjustmentEvent
Answer: D
Q. The signature for the registration method for a ActionEvent should be _______.
Answer: D
A. Window
B. RadioButton
C. ScrollBar
D. None
Answer: D
A. KeyListener( )
B. addKeyListener( )
C. addKeyListenerEvent( )
D. eventKeyboardListener( )
Answer: B
Q. Name the method defined in EventObject class that returns the object generated from the event.
A. getEvent( )
B. getObject( )
C. getId( )
D. getSource( )
Answer: D
A. True
B. False
Answer: A
A. Frame
C. Scrollbar
Answer: B
A. FocusEvent
B. MouseEvent
C. WindowEvent
Answer: D
A. ActionEvent
B. ComponentEvent
C. AdjustmentEvent
D. WindowEvent
Answer: D
Q. Which of the following component generate ActionEvent?
A. ScrollBar
B. Window
C. RadioButton
D. None of these
Answer: D
A. ItemListener
B. InputEvent
C. SelectEvent
D. ListEvent
Answer: A
A. getCommandName( )
B. getActionEventCommand( )
C. getActionCmd( )
D. getActionCommand( )
Answer: D
A. ActionEvent
B. ItemEvent
C. TextEvent
D. All of above
Answer: D
Q. When we need to use Checkbox or Item from the list or use a checkable Menu an __________ is
generated.
A. ActionEvent
B. ItemEvent
C. MenuEvent
D. ClickEvent
Answer: B
A. WINDOW_ACTIVATED
B. WINDOW_CLOSED
C. WINDOW_DEICONIFIED
D. None of these
Answer: D
D. All of these
Answer: C
Answer: C
Q. Which class is used for this processing method processActionEvent( ) method?
B. Button,Checkbox,Choice
Answer: A
Q. Which of this package contains all the classes and methods required for event handling in Java.
A. java.applet
B. java.awt
C. java.event
D. java.awt.event
Answer: D
Q. Name the method defined in EvenObject class that returns the object generated from the event.
A. getEvent( )
B. getObject( )
C. getId( )
D. getSource( )
Answer: D
A. ComponentListener
B. ContainerListener
C. ActionListener
D. InputListener
Answer: C
B. ActionListener
C. FlowListener
D. Adapter
Answer: B
Q. Clicking the closing button on the upper right corner of a frame generates a (n)‐event.
A. ItemEvent
B. WindowEvent
C. MouseMotionEvent
D. ComponentEvent
Answer: B
Q. 35 Which of the following method must be overridden in the order to handle KeyEvent.
A. keyPressed(KeyEvent obj)
B. KeyReleased(KeyEvent obj)
C. KeyTyped(KeyEvent obj)
D. All of these
Answer: D
Q. Which of these methods can be used to know the degree of adjustment made by the user?
A. getValue( )
B. getAdjustmentType( )
C. getAdjustmentValue( )
D. getAdjustmentAmount( )
Answer: C
A. ComponentEvent
B. ContainerEvent
C. ItemEvent
D. InputEvent
Answer: D
A. Listener
B. Sources
C. Event
Answer: A
Answer: A
It is lightweight.
architecture.
A. Swing
B. AWT
C. Both A & B
Answer: A
Q. Swing is not a part of JFC (Java Foundation Classes) that is used to create GUI application?
A. True
B. False
Answer: B
Q. The Swing Component classes that are used in Encapsulates a mutually exclusive set of buttons?
A. AbstractButton
B. ButtonGroup
C. JButton
D. ImageIcon
Answer: B
Q. The Java Foundation Classes (JFC. is a set of GUI components which simplify the development of
desktop applications?
A. True
B. False
Answer: A
components?
A. java.swing
B. java.awt
C. javax.swing
Answer: C
Answer: C
Answer: B
A. java.swing
B. javax.swing
C. java.awt.
Answer: B
A. AbstractButton
B. JButton
C. Button
D. JRadioButton
Answer: A
A. java.awt
B. java.applet
C. java.swing
D. javax.swing
Answer: D
A. JTextArea
B. JTable
C. JPanel
D. JtabbedPane
Answer: B
A. JTree(TreeNode tn)
B. JTree(Vector v)
C. JTree(int x)
Answer: C
A. TreeNode
B. DefaultMutableNode
C. DefaultMutableTreeNode
D. Node
Answer: D
A. java.awt
B. java.swing
C. java.awt.swing
D. javax.swing
Answer: D
Answer: A
Answer: C
A. setDiableIcon( )
B. setPressedIcon( )
C. setSelectedIcon( )
D. setRollOverIcon( )
Answer: C
A. Icon getIcon( )
B. ImageIcon getImageIcon( )
C. ImageIcon getIcon( )
D. ImageIcon GetImageIcon( )
Answer: C
A. JLabel
B. JButton
C. JImageIcon
D. JCheckBox
Answer: C
A. Button, Checkbox
B. JCheckBox,JRadioButton
C. Button, MenuItem
D. JCheckBox, TextField
Answer: B
It is lightweight.
architecture.
A. Swing
B. AWT
C. Both A & B
Answer: A
Q. Swing is not a part of JFC (Java Foundation Classes) that is used to create GUI application?
A. True
B. False
Answer: B
Q. The Swing Component classes that are used in Encapsulates a mutually exclusive set of buttons?
A. AbstractButton
B. ButtonGroup
C. JButton
D. ImageIcon
Answer: B
Q. The Java Foundation Classes (JFC. is a set of GUI components which simplify the development of
desktop applications?
A. True
B. False
Answer: A
components?
A. java.swing
B. java.awt
C. javax.swing
Answer: C
Answer: B
A. java.swing
B. javax.swing
C. java.awt.
Answer: B
A. AbstractButton
B. JButton
C. Button
D. JRadioButton
Answer: A
A. java.awt
B. java.applet
C. java.swing
D. javax.swing
Answer: D
Q. Which component is swing represents data in row and columns?
A. JTextArea
B. JTable
C. JPanel
D. JtabbedPane
Answer: B
A. JTree(TreeNode tn)
B. JTree(Vector v)
C. JTree(int x)
Answer: C
A. TreeNode
B. DefaultMutableNode
C. DefaultMutableTreeNode
D. Node
Answer: D
A. java.awt
B. java.swing
C. java.awt.swing
D. javax.swing
Answer: D
Q. What is purpose of JTree?
Answer: A
Answer: C
A. setDiableIcon( )
B. setPressedIcon( )
C. setSelectedIcon( )
D. setRollOverIcon( )
Answer: C
A. Icon getIcon( )
B. ImageIcon getImageIcon( )
C. ImageIcon getIcon( )
D. ImageIcon GetImageIcon( )
Answer: C
B. JButton
C. JImageIcon
D. JCheckBox
Answer: C
A. Button, Checkbox
B. JCheckBox,JRadioButton
C. Button, MenuItem
D. JCheckBox, TextField
Answer: B