0% found this document useful (0 votes)
2 views7 pages

Java MCQ

The document contains a series of multiple-choice questions (MCQs) related to Java programming, covering topics such as layout managers, event handling, AWT components, exception handling, and constructors. Each question includes options and the correct answers are indicated. The document is structured by weeks, with varying percentages indicating the completion or correctness of the responses.

Uploaded by

harshankit51
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Java MCQ

The document contains a series of multiple-choice questions (MCQs) related to Java programming, covering topics such as layout managers, event handling, AWT components, exception handling, and constructors. Each question includes options and the correct answers are indicated. The document is structured by weeks, with varying percentages indicating the completion or correctness of the responses.

Uploaded by

harshankit51
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Java MCQ

1
Java week 15 40%
. Which Layout Arranges the components horizontally? **Flow Layout,
Border layout, grid layout, card layout
. What layout manager should You use so that every component
5
occupies the same size in the container?
**Grid Layout only, flow layout only, Border Layout and Grid Layout,
any layout
. _______ arranges the components horizontally **Flow layout (same as
question 1)
. Arranges the components as a deck of cards such that only one
component is visible at a time
4
**Card Layout, Border layout, grid layout, Flow Layout
. Which of these stream contains the classes which can work on
3
character stream? [Reader and Writer classes like
InputStreamReader, BufferedReader]
4
**CharachterStream, InputStream, OutputStream, ByteStream
3
2
1
Java week 14 100%
2
[TODO revise week 13,14 i) Read the long answer submitted ii) online
1
class 10
All awt components, their constructors, event listeners and events
classes. ]
. What does AWT stands for? **Abstract Window Toolkit
. The various controls supported by AWT are:
. **All of these
. Labels, push buttons
. Checkboxes, choice list
. Scroll bar, text fields, text area

. The exclusive checkboxes are called as _____ ** Radiobutton, List,


5
choice control, Checkbox
. What does the following line of code do?
Textfield text = new Textfield(10);
1. **Create the text object that can hold 10 columns of text
4
2. Create the text object that can hold 10 rows of text
3. Create the text object that and intitliazises with value 10
3
4. The code is illegal

. Which are passive controls that do not support any interaction with
the user? ** container , frame, window , panel
2
Java Week 13 100%
1
. Which of these packages contains all the classes and methods
2
1
.
required for even handling in Java?
. **java.awt.event 2.java.awt 3. java.event 4. java.applet
1
. What is an event in delegation event model used by Java programming
language?
. ** An event is an object that describes a state change in a
source.
. An event is an object that describes a state change in processing
. An event is an object that describes any change by the user and
the system
. An event is a class used for defining objects to create events
. Which of these methods are used to register a keyboard event
listener? ** addKeyListener(), eventKeyboardListener(), KeyListener()
. Which of these methods are used to register a mouse motion listener?
addMouse(), addMouseLitener(), **addMouseMotionListener(),
eventMouseMotionListener()
. What is a listener in context to event handling?
. **A listener is an object that is notified when an event occurs
. A listener is an variable that is notified when an event occurs
. A listener is an method that is notified when an event occurs
. None of the mentioned
. Which of these events is generated when a button is pressed?
. KeyEvent 2 WindowEvent 3 *ActionEvent 4 AdjustmentEvent
. Which of these interfaces define a method actionPerformed()?
. InputListener 2. ComponentListener 3. **ActionListener 4.
Container Listener
. What is the preferred way to handle an object's events in Java 2?
. **Add one or more event listeners to handle the events
. Override the objects handleEvent() method
. Have the object override dispatch event() method
. Have the object override its process Event() methods
. In itemStateChanged( ) method, we must pass object of
______________ class.
. ActionEvent 2. EventAction 3** ItemEvent 4. EventItem
. Which of these are constants defined in WindowEvent class?
1. WINDOW_CLOSED 2. WINDOW_DEICONIFIED 3. WINDOW_ACTIVATED
4. **All of the above

TODO Week 12 Utility class 80% Q5 has same option twice [TODO read on
date relatable, observable / observer methods] ANSWERS FROM 2nd ATTEMPT
Which string method eliminates whitespaces before and after tokens? **trim(),
intern(), format(), join()
How to format date from one form to another? **SimpleDateFormat,
DateFormat, SimpleFormat, DateConvertor
How to get difference between two dates? ** ong diffInMilli =
java.time.Duration.between(dateTime1, dateTime2).toMillis();

Which of these methods is called when observed object has changed?


**update(), setChanged(), notifyObserver, all of the mentioned
Which of these package provides the ability to read and write in Zip format?
*java.util.zip, java.util.zip, java.io, java.lang

MCQ Week11 80% possibly because of Q3 add() . Expected addElement()?


With this got 100% although wrong
. Which of these are legacy classes? Stack, hash table, vector, *all of
the above
. Which of these is the interface of legacy? *Enumeration, Map,
HashMap, Vector
. Which of these methods is used to add elements in vector at specific
location? *add(), addElement(), AddElement(), set()
. Code snippet involving Vector.addElement() and obj.elementAt(i)
ANS 2
. Code snippet using Stack… push(), push(), pop(), push() then print
the stack . ANS[3,5]
Java MCQ week 10 [only 5 questions] 4/5 80%
. In java a thread can be created by .......... *both of the above
. How many threads can be executed at a time? *10,0,3,1
Which will contain the body of the thread?
start(), main(), *run(), stop()
Which of these method of Thread class is used to Suspend a thread for a
period of time?
terminate() suspend() *sleep() stop()
Which function of pre defined class Thread is used to check weather current
thread being checked is still running?
*isAlive(), Alive, isRunning, join

Java MCQ week 8 80%


Which of these access specifiers must be used for main() method? **public ,
private, protected
Which of these is used to access a member of class before object of that class
is created? **static, public , private, protected
What is the process by which we can control what parts of a program can
access the members of a class? ** encapsulation, recursion, abstraction,
polymorphism
What will be the output of the following Java code? **compilation error {at line
18 obj.y …y is private variable access}
.
. class access
. {
. public int x;
. private int y;
. void cal(int a, int b)
. {
. x = a + 1;
. y = b;
. }
. }
. public class access_specifier
. {
. public static void main(String args[])
. {
. access obj = new access();
. obj.cal(2, 3);
. System.out.println(obj.x + " " + obj.y);
. }
. }

What will be the output of the following Java code? **7 9


. class static_out
. {
. static int x;
. static int y;
. void add(int a, int b)
. {
. x = a + b;
. y = x + b;
. }
. }
. public class static_use
. {
. public static void main(String args[])
. {
. static_out obj1 = new static_out();
. static_out obj2 = new static_out();
. int a = 2;
. obj1.add(a, a + 1);
. obj2.add(5, a);
. System.out.println(obj1.x + " " + obj2.y);
. }
. }
Java MCQ week9 Exception 100%
When does Exceptions in Java arises in code sequence? *Runtime, compile
time, anytime, none of the mentioned
Which of these keywords must be used to monitor exceptions? *Try , catch ,
throw, finally
Which of these keywords is used to manually throw an exception? *Try, throw,
batch, finally
What will be the output of the following Java program?
. class exception_handling
. {
. public static void main(String args[])
. {
. try
. {
. int i, sum;
. sum = 10;
. for (i = -1; i < 3 ;++i)
. sum = (sum / i);
. }
. catch(ArithmeticException e)
. {
. System.out.print("0");
. }
. System.out.print(sum);
. }
. }
0
5
*Compilation error
Run time error

Java week 5 MCQ


. A Java constructor is like a method without ______ **return types
argument list statements none
2. The placement of a constructor inside a class should be ___. Always at the
beginning of the class Always at the end of the class **anywhere in the
class none
. Memory is allocated to an object once the execution of ___ is over in
Java language. *constructor main method destructor none
. Overloading of constructors in Java means adding more than ___
constructors with the different argument list. *1 2 3 4
. A constructor can call another overloaded constructor using the ___
keyword in Java. **this local super con
Java week 4 MCQ
. What do you mean by nameless objects?
*an object that has no reference
. Which of the following is true about the anonymous inner class?
It has only methods Objects can’t be created it has fixed class name **it
has no class name
. What option is false about the final key word? A final method cannot
be overridden in its subclass b.a final class cannot be extended c
**final class cannot extend other classes d a final method can be
inherited
. Which of the following is a mutable class in Java? Java.lang.String
java.lang.Byte java.lang.Short ** java.lang.StringBuilder
. What is meant by classes and objects that depend on each other?
**Tight coupling cohesion loose coupling none

Java week 3 McQ 90%


. Java Source Code is compiled into ______________. a. Source code, b
obj c exe *d Bytecode
. Which class provides stream to read binary data such as image etc.
from the request object? *A, ServletInputStream b
ServletOutputStream c Both A & B D. None of the above
. Which of the following is used to interpret and execute Java Applet
Classes hosted by HTML. AppletShow * AppletViewer appletWatcher
appletScreen
. Java servlets are an efficient and powerful solution for creating
………….. for the web. a*. Dynamic content b. Static content c.
Hardware d Both A and B
5. Which is used for reading streams of raw bytes such as image data and for
reading streams of characters, consider using FileReader?
A.* FileInputStream B FileOutputStream C both A & B d none of the above
. The command javac is used to _______. a. Debug b*compile c
interpret d execute
. Which method is used to change the name of a thread? *Public void
setName(String) , public String getName() , public void getName,
public String setName(String name)

. What will be the output of the program?


class PassA
{
public static void main(String [] args)
{
PassA p = new PassA();
p.start();
}
void start()
{
long [] a1 = {3,4,5};
long [] a2 = fix(a1);
System.out.print(a1[0] + a1[1] + a1[2] + " ");
System.out.println(a2[0] + a2[1] + a2[2]);
}

long [] fix(long [] a3)

{
a3[1] = 7;
return a3;
}
}
*****important a. 12 15 b*15 15 c3 4 5 3 7 5 d 3 7 5 3 7 5
. Java programs are ____________. Faster than others, *platform
independent, not reusable, not scalable
. What of the following is the default value of a local variable? Null, zero,
depends upon type, *unassigned <compile time error >

You might also like