100% found this document useful (1 vote)
562 views

Part - 2 - OOP Sample Questions

The document contains sample questions and answers related to object-oriented programming and Java concepts like input/output, packages, classes, threads, generics, and file handling. There are over 50 multiple choice questions testing knowledge of Java packages, I/O classes, threading concepts like priorities and states, generic types, and file reading/writing classes.

Uploaded by

Shreya Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
562 views

Part - 2 - OOP Sample Questions

The document contains sample questions and answers related to object-oriented programming and Java concepts like input/output, packages, classes, threads, generics, and file handling. There are over 50 multiple choice questions testing knowledge of Java packages, I/O classes, threading concepts like priorities and states, generic types, and file reading/writing classes.

Uploaded by

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

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

D. All of the mentioned

Answer: C

Q. Which of these class is not a member class of java.io package?

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

D. All of the mentioned

Answer: A

Q. Which of these class is used to read characters in a file?

A. FileReader

B. FileWriter

C. FileInputStream

D. InputStreamReader
Answer: A

Q. URL is an acronym for?

A. Uniform Resource Locator

B. Unified Resource Locator

C. Uniform Restore Locator

D. Unified Restore Locator

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

D. None of the above

Answer: A

Q. Which of these package contains classes and interfaces for networking?

A. javA.io

B. javA.util

C. javA.net

D. javA.network

Answer: C

Q. How many ports of TCP/IP are reserved for specific protocols?

A. 10

B. 1024

C. 2048

D. 512

Answer: B
Q. What are the 2 possible way to create thread in Java?

A. using thread and runnable

B. using run and start

C. using MyThread and MyRunnable

D. none of these

Answer: A

Q. Which method is need to override for writing multithreading code?

A. start method

B. run method

C. create method

D. main method

Answer: B

Q. Which method is used to display current thread name is Java?

A. getThreadName()

B. getName()

C. displayThreadName()

D. currentThreadName()

Answer: B

Q. What is value of ThreaD.MAX_PRIORITY?

A. 1

B. 5

C. 10

D. 8

Answer: C
Q. In java multi-threading, a thread can be created by

A. Extending Thread class

B. Implementing Runnable interface

C. Using both

D. None of these

Answer: C

Q. What is maximum thread priority in Java

A. 10

B. 12

C. 5

D. 8

Answer: A

Q. What is meant by the term generics?

A. parameterized types

B. class

C. structure

D. interface

Answer: A

Q. Choose the advantages of using generics?

A. Generics facilitate type safety

B. Generics facilitate improved performance and reduced code

C. Generics promote the usage of parameterized types

D. All of the mentioned

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

Q. Class start with J letter comes under _______

A. AWT

B. Applets

C. Swing

D. Swift

Answer: C

Q. Which is not advantage of Swing over AWT?

A. Swing is light weight, AWT is heavy weight

B. Swing interface is native to OS, AWT have Java interface

C. Swing is faster than AWT

D. AWT is better than Swing.

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

Q. Which is used for writing data to a file in file handling?

A. FileInputStream

B. FileOutputStream

C. Both A & B

D. None of the above

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

D. None of the above

Answer: A

Q. Which are the ways to read data from the keyboard?

A. InputStreamReader

B. Console

C. Scanner

D. All Mentioned above

Answer: D

Q. Which class can be used to read data line by line by readLine() method?

A. BufferedReader

B. InputStreamReader

C. DataInputStream

D. None of the above

Answer: A

Q. In how many states Threads can be explained ?

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?

A. public void start()

B. public void run()


C. public void stop()

D. public coid suspend()

Answer: A

Q. Can we start a thread twice?

A. Yes

B. No

Answer: B

Q.Which method waits for a thread to die?

A. stop()

B. start()

C. terminate()

D. join()

Answer: D

Q. Which method returns a reference to the currently executing thread object?

A. currentThread()

B. runningThread()

C. runnableThread()

D. None of the above

Answer: A

Q. In Naming a thread which method is used to change the name of a thread?

A. public String getName()

B. public void setName(String name).

C. public void getName()

D. public String setName(String name)

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

Q. Which of the following cannot be Type parameterized?

A. Overloaded Methods

B. Generic methods

C. Class methods

D. Overriding methods

Answer: A

Q. What will be the output of the following program?

public class UseGenerics {


public static void main(String args[]){

MyGen<Integer> m = new MyGen<Integer>();

m.set("merit");

System.out.println(m.get());

class MyGen<T>

T var;

void set(T var)

this.var = var;

T get()

return var;

A. merit

B. 0

C. Compilation Error

D. Runtime Error

Answer: B

Q. At what line will there be a compilation error?

public class Generics {

public static void main(String[] args) {

B b = new B(); /* LINE A */

C c = b.process(new C()); /* LINE B */


B<C> b2 = new B<C>(); /* LINE C */

C c2 = b2.process(new C()); /* LINE D */

interface A {

int count();

void show();

class B<T extends A> {

T process(T t) {

t.count();

t.show();

return t;

class C implements A {

public int count() { return 25; }

public void show() { System.out.print("Class C"); }

A. LINE A

B. LINE B

C. LINE C

D. LINE D

Answer: B

Q. What will be the output of the following program?

public class GenericsWithObjectsDemo {

public static void main(String args[])

{
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

B. Some other output

C. Compilation Error

D. Runtime Error

Answer: C

Q. Why are generics used?

A. Generics make code more optimised and readable.

B. Generics make code more fast.

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.*;

public class SampleDemo {

public static void main(String args[]) {

Sample <Integer> obj = new Sample<Integer>();

obj.push(36);

System.out.println(obj.pop());

class Sample<E>

Stack <E> ob = new Stack <E>();

public void push(E obj) {

ob.push(obj);

public E pop() {

E obj = ob.pop();

return obj;

A. 36

B. Some Other Output

C. Compilation Error

D. Runtime Error

Answer: A

Q. Which of these are types of multitasking?

a) Process based

b) Thread based
c) Process and Thread based

d) None of the mentioned

Answer: C

Q. Thread priority in Java is?

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?

a) Anyone will be executed first lexographically

b) Both of them will be executed simultaneously

c) None of them will be executed

d) It is dependent on the operating system

Answer: D

Q. Which of these statements is incorrect?

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

c) Two thread in Java can have the same priority

d) A thread can exist only in two states, running and blocked

Answer: D

Q. What will be the output of the following Java code?

class multithreaded_programing

public static void main(String args[])


{

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

Q. What is the priority of the thread in the following Java Program?

class multithreaded_programing

public static void main(String args[])

Thread t = Thread.currentThread();

System.out.println(t);

a) 4

b) 5

c) 0

d) 1

Answer: B

Q. What is the name of the thread in the following Java Program?


class multithreaded_programing

public static void main(String args[])

Thread t = Thread.currentThread();

System.out.println(t);

a) main

b) Thread

c) System

d) None of the mentioned

Answer: A

Q. What is maximum thread priority in Java

A. 10

B. 12

C. 5

D. 8

Answer: A

Q. Which method must be implemented by a Java thread?

A. run()

B. execute()

C. start()

D. None

Answer: A

Q. Number of threads in below java program is


public class ThreadExtended extends Thread {

public void run() {

System.out.println("\nThread is running now\n");

public static void main(String[] args) {

ThreadExtended threadE = new ThreadExtended();

threadE.start();

Answer: C

Q. Which method is used to check if a thread is running?

A. isAlive()

B. run ()

C. alive ()

D keepAlive()

Answer: A

Q. Min and Max priority of a thread in Java multithreading are

A. 1, 10

B. 0,10
C. 0,255

D. 1,256

Answer: A

Q. Which method we implement from Runnable interface?

A. run ()

B. start ()

C. execute ()

D. call ()

Answer: A

Q. Daemon thread runs in

A. Background

B. Foreground

C. Both

D. none

Answer: A

Q. Which method is used to create a daemon thread?

A. setDaemon(boolean value)

B. setThread(boolean value)

C. createDaemon(boolean value)

D. makeDeamon(boolean value);

Answer : A

Q. To create a daemon thread

A. First thread setDaemon() is called then start()

B. First thread start() is called then setDaemon()

C. Call thread start() and setDaemon() in any order


D. All correct

Answer: A

Q. Which will contain the body of the thread in Java?

A. start()

B. run()

C. Main()

D. execute()

Answer: B

Q. Thread synchronization in a process will be required when

A. All threads sharing the same address space

B. All threads sharing the same global variables

C. All threads sharing the same files

D. All

Answer: D

Q. Which method is used to get current running thread object?

A. runningThread()

B. currentThread()

C. runnableThread()

D. None

Answer: B

Q. Give the abbreviation of AWT ?

A. Applet Windowing Toolkit

B. Abstract Windowing Toolkit


C. Absolute Windowing Toolkit

D. None of the above

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

Q. AWT is used for GUI programming in java?

A. True

B. False

Answer: A

Q. Which class provides many methods for graphics programming?

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

like button, textfield etc?

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

Q. Which are passive controls that do not support any

interaction with the user?

A. Choice

B. List

C. Labels
D. Checkbox

Answer: C

Q. By which method You can set or change the text in a Label ?

A. setText()

B. getText()

C. Both A & B

D. None of the above

Answer: A

Q. Which class is used to create a pop‐up list of items

from which the user may choose?

A. List

B. Choice

C. Labels

D. Checkbox

Answer: B

Q.Which object can be constructed to show any

number of choices in the visible window?

A. Labels

B. Choice

C. List

D. Checkbox

Answer: C

Q. Which is used to store data and partial results, as

well as to perform dynamic linking, return values

for methods, and dispatch exceptions?


A. Window

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

D. None of the above

Answer: B

Q. AWT more powerful components like tables, lists,scroll panes, color chooser, tabbed pane etc.?

A. True

B. False

Answer: A

Q. These four methods commonly used in?

(i) public void add(Component c)

(ii) public void setSize(int width,int height)

(iii) public void setLayout(LayoutManager m)

(iv) public void setVisible(boolean)

A. Graphics class

B. Component class

C. Both A & B

D. None of the above

Answer: B
Q. In Graphics class which method is used to draws a rectangle with the specified width and height?

A. public void drawRect(int x, int y, int width, int height)

B. public abstract void fillRect(int x, int y, int width, int height)

C. public abstract void drawLine(int x1, int y1, int x2, int y2)

D. public abstract void drawOval(int x, int y, int width, int height)

Answer: B

Q. Implement the Listener interface and overrides its methods is required to perform in event handling?

A. True

B. False

Answer: A

Q. Public class MenuBar extends ____________.

A. MenuComponent

B. MenuContainer

C. ComponentMenu

D. MenuBar

Answer: A

Q. Which of the following is true about AWT and Swing components.

A. AWT components creates a process where as swing components creates a thread

B. AWT components creates a thread where as swing components creates a process

C. Both AWT and Swing components creates a process

D. Both AWT and swing components creates a thread

Answer: C

Q. Panel is defined as ______________.

A. The Panel class is a concrete subclass of Container.

B. A Panel is a window that does not contain titlebar, menubar and border.
C. Panel is a superclass of Applet.

D. All of the above.

Answer: D

Q. What is API?

A. Application Programming Interchange

B. Application Programming Interaction

C. Application Programming Interface

D. None of these

Answer: C

Q. What is default layout for Dialog?

A. FlowLayout

B. GridLayout

C. CardLayout

D. BorderLayout

Answer: A

Q. Which method is used to count the number of items is the List.

A. getItem( )

B. getSelectedItem( )

C. getItemCount( )

D. getCount( )

Answer: C

Q. The correct hierarchy for Panel is __________

A. Component – Container – Window – Panel

B. Component – Container – Applet – Panel

C. Component – Container – Panel


D. Container – Component – Panel

Answer: C

Q. Which is the correct constructor of GridLayout.

A. GridLayout(int a)

B. GridLayout(int num_rows, int num_columns)

C. GridLayout(int rows, int cols, int vert)

D. GridLayout(int hor)

Answer: B

Q. What are the types of DialogBox?

A. Modal DialogBox

B. Modal and Modeless DialogBox

C. Modam

D. None of the above

Answer: B

Q. In the give constructor what third parameter indicates :

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

Q. To set the title to the Frame window ________method is used.

A. void setTitle(String str)

B. void setText(String str)

C. void settitle(String str)

D. None of the above

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?

A. 12 point Times New Roman

B. 11 point Times New Roman

C. 10 point Times New Roman

D. 9 point Times New Roman

Answer: C

Q. Which of the following is true about FlowLayout?

A. FlowLayout can use multiple rows if the horizontal space in the container is too small to hold the
component.

B. FlowLayout is the default layout manager of panel and applet.

C. It is the default layout manager for window.

D. Both A & B.

Answer: D

Q. Which of the method can be used to output a String in an Applet?

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

Q. Panel is defined as _______.

A. Panel class is a concrete sub‐class of container

B. A Panel is a window that does not contain a title bar, menu bar or border

C. Panel is the superclass of Applet

D. All of above

Answer: D

Q. Which component of AWT provides compact, multichoice, scrolling component?

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

Q. Which method is used to set password character for a TextField?

A. setPasswordCharacter( )

B. setEchoChar( )

C. setPassChar( )

D. setEchoCharacter( )

Answer: B

40Q. The getContentPane( ) method is of which class?

A. JApplet

B. JFrame

C. JButton

D. None of these

Answer: D

Q. Which class defines setSize( ) method?

A. Frame

B. Applet

C. Component

D. Panel

Answer: C

Q. __________ is a swing class that allows to enter a single line of text.

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

Q. What is use of second parameter in given constructor Lable(String,int)

A. specifies height of label

B. specifies width of label in terms of pixel

C. specifies the alignment of text in label in terms of pixel

D. specifies width of label

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);

A. will set 10 to TextField as its initial text.

B. Will set the character capacity to 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?

A. Derived class / Subclass

B. Base class / Super class

C. Root class

D. Family class

Answer: A

Q. A ____________ is a passive AWT control that do not generate any event?

A. Button

B. RadioButton

C. Choice

D. Label

Answer: D

Q. The default layout manager of Frame is________.

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

Q. Which of the following method is used to set a TextComponent to read‐only mode?

A. Editable( )

B. nonEditable( )

C. setEchoChar( )

D. setEditable( )

Answer: D

Q. _________ generates action events when an item is double‐clicked.

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?

A. swing exists since the version 1.2 of the JDK

B. AWT stands for Abstract Window Toolkit

C. You cannot place AWT component on swing container.

D. The AWT classes are deprecated.

Answer: C

Q. Which of the following package is used for Graphical User Interface?

A. java.applet

B. java.awt

C. java.awt.image

D. java.io

Answer: B

Q. What are the variables defined in Dimension?

A. length and width

B. height and length

C. height and width

D. None of these

Answer: C

Q. Which AWT component is not editable?

A. Button

B. TextField

C. FlowLayout

D. Label

Answer: B

Q. Current text of Label can be obtained using __________.


A. setAlignment( )

B. getAlignment( )

C. getText( )

D. setText( )

Answer: C

Q. The method ___________ places a Menu m into the MenuBar mb.

A. mb.addMenuItem(m)

B. mb.addItem(m)

C. mb.add(m)

D. None of these

Answer: C

Q. Which of these Components cannot be added to Frame?

A. Label

B. Button

C. CheckboxGroup

D. All of above

Answer: C

Q. What is use of second parameter given in Label constructor : Label(String, int)

A. Specifies height of label in terms of pixels.

B. specifies width of label in terms of pixels.

C. specifies the alignment of text in label in terms of pixels.

D. Specifies maximum numbers of characters in label.

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

Q. What is the use of setEchoChar( ) method?

A. to set echo in symbol form

B. to set char in symbol form

C. Both A & B

D. to create password in symbol form

Answer: C

Q. __________ method returns currently selected

item in choice.

A. getSelectedItem( )

B. getSelectedElement( )

C. getSelectedIndex( )

D. getItem( )

Answer: A

Q. The default layout of Applet is _______.

A. GridLayout

B. CardLayout

C. FlowLayout

D. BorderLayout

Answer: C

Q. Java Applets are used to create ________ applications.


A. Graphical

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

D. None of the above

Answer: C

Q. In which places can put the event handling code

A. Same class

B. Other class

C. Annonymous class

D. All mentioned above

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

D. None of the above

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?

A. Creating a new class

B. using the class the graphical component

C. an anonymous inner class

D. All mentioned above

Answer: D

Q. The ActionListener interface is not used for handling action events?

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

Q. Which class is used for this Processing Method processActionEvent( )?

A. Button,List,MenuItem

B. Button,Checkbox,Choice

C. Scrollbar,Component,Button

D. None of the above

Answer: A

Q. In Graphics class Which method is used to set the graphics current color to the specified color?

A. public abstract void setFont(Font font)


B. public abstract void setColor(Color c)

C. public abstract void drawString(String str, int x, int y)

D. None of the above

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

Q. TextField generates ____________ event.

A. ActionEvent,ItemEvent

B. ActionEvent, TextEvent

C. ScrollEvent,TextEvent

D. ActionEvent, ScrollEvent

Answer: B

Q. void keyTyped(KeyEvent ke) called when a key on the keyboard is ____________.

A. pressed and then released.

B. pressed

C. released

D. none of the above

Answer: A

Q. Which event is generated when the position of scrollbar is changed?

A. KeyEvent

B. MouseEvent
C. ItemEvent

D. AdjustmentEvent

Answer: D

Q. The signature for the registration method for a ActionEvent should be _______.

A. public void addActionListener(ActionEvent L)

B. public void setAction(ActionListener L)

C. public void setActionListener(ActionListener L)

D. public void addActionListener(ActionListener L)

Answer: D

Q. Which of the following component generates ActionEvent?

A. Window

B. RadioButton

C. ScrollBar

D. None

Answer: D

Q. ___________ method is used to register a keyboard event listener.

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

Q. The MouseListener interface is used to make mouse handling.

A. True

B. False

Answer: A

Q. ActionEvent is applied on ________

A. Frame

B. Checkbox, Choice, List

C. Scrollbar

D. Button, TextField, List, Menu

Answer: B

Q. ComponentEvent is the super class of __________.

A. FocusEvent

B. MouseEvent

C. WindowEvent

D. All of the above

Answer: D

Q. If we close an applet window _________ events will be generated.

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

Q. Which Listener handles all List related Events?

A. ItemListener

B. InputEvent

C. SelectEvent

D. ListEvent

Answer: A

Q. How to obtain the command name for invoking ActionEvent?

A. getCommandName( )

B. getActionEventCommand( )

C. getActionCmd( )

D. getActionCommand( )

Answer: D

Q. ComponentEvent is the superclass of________

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

Q. Which of the following constant is not defined in WindowEvent class?

A. WINDOW_ACTIVATED

B. WINDOW_CLOSED

C. WINDOW_DEICONIFIED

D. None of these

Answer: D

Q. Which of the following is not the method of handling window event?

A. void windowClosed(WindowEvent we)

B. void windowClosing(WindowEvent we)

C. void windowAfterClosing(WindowEvent we)

D. All of these

Answer: C

Q. Which method is used to process mouse click?

A. public void mouseClicked(MouseListener m)

B. public void mouseIsClicked(MouseEvent m)

C. public void mouseClicked(MouseEvent m)

D. public void mouseClick(MouseEvent m)

Answer: C
Q. Which class is used for this processing method processActionEvent( ) method?

A. Button, List, MenuItem

B. Button,Checkbox,Choice

C. ScrollBar, Component, Button

D. None of the above.

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

Q. Which of these interfaces define a method actionPerformed()

A. ComponentListener

B. ContainerListener

C. ActionListener

D. InputListener

Answer: C

Q. Button Control implements following listener interface.


A. ItemListener

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

Q. MouseEvent is subclass of which of the following class?

A. ComponentEvent
B. ContainerEvent

C. ItemEvent

D. InputEvent

Answer: D

Q. The _________ is an object that is notified when an event occurs.

A. Listener

B. Sources

C. Event

D. None of the above

Answer: A

Q. What is the use of String getActionCommand( ) method of ActionEvent class?

A. to obtain the label (caption) of Button

B. to obtain the reference of Button

C. to obtain object of Button

D. to obtain the label (caption) and object of

Answer: A

Q. The following specifies the advantages of

It is lightweight.

It supports pluggable look and feel.

It follows MVC (Model View Controller)

architecture.

A. Swing

B. AWT

C. Both A & B

D. None of the above

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

Q. Which package is used for import the swing

components?

A. java.swing

B. java.awt

C. javax.swing

D. All of the above

Answer: C

Q. The String parameter to JButton constructor ______________.

A. tell which region to put the JButton in.


B. tells the color of the JButton.

C. tells what text will appear on JButton.

D. tells what should happen when JButton is pressed.

Answer: C

Q. MVC architecture is _________

A. Modelling – Visual – Controller

B. Model – View – Controller

C. Model – Viewable – Controller

D. Many – View – Controller

Answer: B

Q. Which package is used for imporing swing components?

A. java.swing

B. javax.swing

C. java.awt.

D. All of the above

Answer: B

Q. In swing, Buttons are subclasses of which class?

A. AbstractButton

B. JButton

C. Button

D. JRadioButton

Answer: A

Q. JTree class belongs to which package?

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

Q. Which of the following is not constructor of JTree?

A. JTree(TreeNode tn)

B. JTree(Vector v)

C. JTree(int x)

D. none of the above

Answer: C

Q. ____________class used to create node in tree.

A. TreeNode

B. DefaultMutableNode

C. DefaultMutableTreeNode

D. Node

Answer: D

Q. JTabbedPane class is present in which package?

A. java.awt

B. java.swing

C. java.awt.swing
D. javax.swing

Answer: D

Q. What is purpose of JTree?

A. To show data in form of parent and childnodes.

B. To show data in list view.

C. To show data in tabular form.

D. To show data in menu‐bar.

Answer: A

Q. What is the use of : Container getContentPane( )

A. Returns Container for a JDialog.

B. Returns a ContentPane for Menu

C. Returns a ContentPane for Applet

D. None of the above

Answer: C

Q. Which of the following method is not applicable for Button in swing.

A. setDiableIcon( )

B. setPressedIcon( )

C. setSelectedIcon( )

D. setRollOverIcon( )

Answer: C

Q. Which of the following method is used to retrieve icon of JButton?

A. Icon getIcon( )

B. ImageIcon getImageIcon( )

C. ImageIcon getIcon( )

D. ImageIcon GetImageIcon( )
Answer: C

Q. From following list which is not Swing class?

A. JLabel

B. JButton

C. JImageIcon

D. JCheckBox

Answer: C

Q. Which component provides support for two‐state buttons?

A. Button, Checkbox

B. JCheckBox,JRadioButton

C. Button, MenuItem

D. JCheckBox, TextField

Answer: B

Q. The following specifies the advantages of

It is lightweight.

It supports pluggable look and feel.

It follows MVC (Model View Controller)

architecture.

A. Swing

B. AWT

C. Both A & B

D. None of the above

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

Q. Which package is used for import the swing

components?

A. java.swing

B. java.awt

C. javax.swing

D. All of the above

Answer: C

Q. The String parameter to JButton constructor ______________.

A. tell which region to put the JButton in.

B. tells the color of the JButton.

C. tells what text will appear on JButton.

D. tells what should happen when JButton is pressed.


Answer: C

Q. MVC architecture is _________

A. Modelling – Visual – Controller

B. Model – View – Controller

C. Model – Viewable – Controller

D. Many – View – Controller

Answer: B

Q. Which package is used for imporing swing components?

A. java.swing

B. javax.swing

C. java.awt.

D. All of the above

Answer: B

Q. In swing, Buttons are subclasses of which class?

A. AbstractButton

B. JButton

C. Button

D. JRadioButton

Answer: A

Q. JTree class belongs to which package?

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

Q. Which of the following is not constructor of JTree?

A. JTree(TreeNode tn)

B. JTree(Vector v)

C. JTree(int x)

D. none of the above

Answer: C

Q. ____________class used to create node in tree.

A. TreeNode

B. DefaultMutableNode

C. DefaultMutableTreeNode

D. Node

Answer: D

Q. JTabbedPane class is present in which package?

A. java.awt

B. java.swing

C. java.awt.swing

D. javax.swing

Answer: D
Q. What is purpose of JTree?

A. To show data in form of parent and childnodes.

B. To show data in list view.

C. To show data in tabular form.

D. To show data in menu‐bar.

Answer: A

Q. What is the use of : Container getContentPane( )

A. Returns Container for a JDialog.

B. Returns a ContentPane for Menu

C. Returns a ContentPane for Applet

D. None of the above

Answer: C

Q. Which of the following method is not applicable for Button in swing.

A. setDiableIcon( )

B. setPressedIcon( )

C. setSelectedIcon( )

D. setRollOverIcon( )

Answer: C

Q. Which of the following method is used to retrieve icon of JButton?

A. Icon getIcon( )

B. ImageIcon getImageIcon( )

C. ImageIcon getIcon( )

D. ImageIcon GetImageIcon( )

Answer: C

Q. From following list which is not Swing class?


A. JLabel

B. JButton

C. JImageIcon

D. JCheckBox

Answer: C

Q. Which component provides support for two‐state buttons?

A. Button, Checkbox

B. JCheckBox,JRadioButton

C. Button, MenuItem

D. JCheckBox, TextField

Answer: B

You might also like