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

Core Java MCQ Unit 3

1. Daemon threads run in the background and execute concurrently with user threads. 2. The main thread must call the join() method to wait for all child threads to complete before terminating. 3. The Thread class constructor allows threads to be created by passing a Runnable object and priority.

Uploaded by

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

Core Java MCQ Unit 3

1. Daemon threads run in the background and execute concurrently with user threads. 2. The main thread must call the join() method to wait for all child threads to complete before terminating. 3. The Thread class constructor allows threads to be created by passing a Runnable object and priority.

Uploaded by

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

BCCA SEM IV Core Java

UNIt -III MCQ


Sr.No. Questions A B C D Answer
Execution of a java thread begins on
1 Start () Run () Execute () Launch () A
which method call?
Foregroun
2 Daemon thread runs in Background Both none A
d
Which method is used to make main
3 Join () Sleep () Wait () Stop () A
thread to wait for all child threads
Which method is used to check if a
4 isAlive() run () alive () keepAlive() A
thread is running?
Min and Max priority of a thread in
5 0, 255 0, 10 1, 10 1, 256 C
Java multithreading are
Which method is used to get current runningThre currentThr runnableT
6 None B
running thread object? ad() ead() hread()
Which of these keywords is not a part
7 try finally thrown catch C
of exception handling?
Which of these keywords must be
used to handle the exception thrown
8 try finally throw catch D
by try block in some rational manner?

Which of these keywords is used to


9 try finally throw catch C
manually throw an exception?
The class at the top of exception class ArithmeticE
10 Throwable Object Exception B
hierarchy is .... xception
public public
public
public void abstract abstract
abstract void
In Graphics class which method is drawRect(int void void
drawOval(int
11 used to draws a rectangle with the x, int y, int fillRect(int drawLine(i A
x, int y, int
specified width and height? width, int x, int y, int nt x1, int
width, int
height) width, int y1, int x2,
height)
height) int y2)
Applet Abstract Absolute
None of the
12 Give the abbreviation of AWT? Windowing Window Windowin B
above
Toolkit Toolkit g Toolkit
drawCircle
drawOval( setOval(int newOval(int
( int X, int
Which of the following method is int X, int Y, X, int Y, X, int Y, int
13 Y, int A
used to draw line in java? int width, int int width, width, int
width, int
height ) int height) height)
height )
void void
drawPolygon int void newPolygon(
Which of the following method is (int x[], int Polygon(in polygon(in int x[], int
14 A
used to draw polygon in java? y[], int t x,int y, t x[], int y[], int
numOfPoint int z) y[]) numOfPoint
s) s)
which of the following blocks execute
15 compulsorily whether exception is catch finally throws throw B
caught or not?
Which of these keywords is used to
16 pkg Pkg package Package C
define packages in Java?
17
ArrayInde
Which exception is thrown when an ArrayEleme ArrayInde
xOutOfBo None of
18 array element is accessed beyond the ntOutOfBou xOutOfBo B
undsExcep these
array size? nds unds
tion
NumberFor
Which exception is thrown when NullPointe Arithmetic None of
19 matExceptio B
divide by zero statement executes? rException Exception these
n
Which method we implement from
20 Run () Start () Execute () call () A
Runnable interface?
If a priority of a java thread is 3 then
21 the default priority of its child thread 0 1 5 3 D
will be
How many ways a thread can be
22 1 2 3 4 B
created in Java multithreading?
What is maximum thread priority in
23 5 8 10 12 C
Java
Which method is called internally by
24 execute() run() launch() main() B
Thread start() method?
Thread(Ru
Thread(Runn nnable Thread(Strin
Which of the following constructor of able Thread(int threadOb, g
25 C
class Thread is valid one? threadOb, int priority) String threadName,
priority) threadNam int priority)
e)
When a class extends the Thread
class, it should override ............
26 start() run() init() go() B
method of Thread class to start that
thread.
Which method of Thread class is used
27 to suspend a thread for a period of sleep() terminate() suspend() stop() A
time?
editing classes and
28 A package is a collection of classes interfaces D
tools interfaces
import package main
29 The first statement in java source file class B
statement statement statement
Organizin
g java
for faster
For which purpose packages are used categorizes classes None of the
30 compilatio B
in java? data into mentioned
n
namespace
s
What will be the output of the
following Java program?
package pkg;
class output
{
public static void main(String
args[])
31 { xello xxxxx Hxllo Hexlo C
StringBuffer s1 = new
StringBuffer("Hello");
s1.setCharAt(1, x);
System.out.println(s1);
}
}

Which of the following package


stores all the standard java classes?
a) lang
java.package
32 b) java lang java util B
s
c) util
d) java.packages

Which of the following is the correct


Import import
33 way of importing an entire package import pkg. Import pkg.* C
pkg. pkg.*
‘pkg’?
Which of this access specifies can be
used for a class so that its members no none of the
34 public protected C
can be accessed by a different class in modifier mentioned
the same package?
Wakes up
Wakes up
Wakes up all threads
all threads
one threads that are
that are
What notifyAll() method do? that are not None of the
35 waiting on C
waiting on waiting on above
this
this object's this
object's
monitor object's
monitor
monitor
36
drawLine(int newline(in
line(int x1,
Write the syntax of method to draw x1, int y1, setLine(int t x1,int
37 int y1, int
line. int x2, int x, int y) y1,int x2,
x2, int y2)
y2) int y2)
Write the code to obtain the name of t.currentT
38 t.getName() t.Name() t.Thread() A
thread t hread()
Write the code to obtain the priority t.getPriorit t.getName(
39 t.priority() t.Thread() B
of the current thread t y() )
Classes,
even We can
though have
they are hidden
visible classes
Packages outside that are
Write down the advantages of All of the
40 avoid name their used by D
package above
clashes. package, the
can have packages,
fields but not
visible to visible
packages outside.
only
Name the method that must be
41 run() execute() start() None A
implemented by a Java thread?
42
Which of the following are methods
of the Thread class?
1) yield() None of the
43 1 , 2 and 4 1 and 3 3 only A
2) sleep(long msec) above
3) go()
4) stop()
Analyze the following code:
public class Test implements The
The program
Runnable{ program
has a
public static void main(String[] compiles
compilation
args){ fine, but it The
error
Test t = new Test(); does not program
because t is The program
} run compiles
defined in compiles and
44 public Test(){ because and runs D
both the runs and
Thread t = new Thread(this); you cannot and
main() displays test
t.start(); use the displays
method and
} keyword nothing.
the
public void run(){ this in the
constructor
System.out.println("test"); constructo
Test().
} r.
}
The
Analyze the following code: The
The program program
public class Test implements program
does not compiles,
Runnable{ compiles,
compile but it does
public static void main(String[] but it does
because the not run The program
args){ not run
45 start() because compiles and A
Test t = new Test(); because
method is the run() runs fine.
t.start(); the start()
not defined method is
} method is
in the Test not
public void run() { } not
class. implement
} defined.
ed.
The
The program
program
will not
will not
public abstract class Test implements compile The
compile
Runnable { because it program None of the
46 because it C
public void doSomething() { }; does not compiles above
does not
} implement fine.
contain
the run()
abstract
method.
methods.

what will be the output of the


following program.
class Sample {
public static void main(String
args[])
{
47 0 1 TRUE FALSE C
Thread t =
Thread.currentThread();
System.out.println(t.isAlive());
}
}

48
class Test extends Thread {
public void run()
{
System.out.println("Run");
}
Two Depend
} class Myclass { One thread No thread
49 thread upon A
public static void main(String[] args) created created
created system
{
Test t = new Test();
t.run();
}
}
class Test extends Thread {
public void run()
{
System.out.println("Run");
}
Two Depend
} class Myclass { One thread No thread
50 thread upon B
public static void main(String[] a) created created
created system
{
Test t = new Test();
t.start();
}
}
What will be output of the following
program code?
public class Test implements
Runnable
{
public void run()
{
System.out.print("go"); An
} exception is go is "gogo" is gogogo is
51 D
thrown at printed printed printed
public static void main(String arg[]) runtime.
{
Thread t = new Thread(new Test());
t.run();
t.run();
t.start();
}
}

public class Test extends Thread{


2. public static void main(String
argv[]){
3. Test t = new Test(); Compilati
Compilation
4. t.run(); on fails
run-test fails due to
52 5. t.start(); run-test due to an B
run-test an error on
6. } error on
line 7
7. public void run(){ line 4
8. System.out.print("run-test ");
9. }
10. }
What will be the output of the
The
following program code?
program
public class Test implements
The program compiles
Runnable{ The
does not fine, but it
public static void main(String[] program
compile does not
args){ compiles
because this print None of the
53 Thread t = new Thread(this); and runs A
cannot be anything above
t.start(); fine and
referenced in because t
} displays
a static does not
public void run(){ test on the
method. invoke the
System.out.println("test"); console.
run()
}
method
}
Answer

You might also like