Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
JAVA LANGUAGE
MULITPLE CHOICE
QUESTION SET-4
1. If an exception is generated in
try block, then it is caught in ----block
finally
throw
throws
catch
www.prolearninghub.com
2. To explicitly throw an
exception, ------ keyword is used.
try
catch
throw
throwing
www.prolearninghub.com
3. ------ is a super class of all
exception classes.
Exception
Throwable
RuntimeException
IOException
www.prolearninghub.com
4. Exception is subclass of ---class
Exception
Throwable
RuntimeException
IOException
www.prolearninghub.com
5. When a method can throw an
exception then it is specified by ---- keyword
finally
throw
throws
catch
www.prolearninghub.com
6. Which block gets executed
compulsory whether exception is
caught or not.
finally
throw
throws
catch
www.prolearninghub.com
7. To create our own exception
class, we have to ------Extend exception class
Create our own try and
catch block
Use finally block
Use throws keyword
www.prolearninghub.com
8. Which block of must be
executed to check that exception
is catched or not?
Finally
Throws
Throw
Try
www.prolearninghub.com
9. The super class exception
cannot catch first if?
There is multiple catch
block
There is one catch
block
There is no catch
block
None of above
www.prolearninghub.com
10. What type of exception
parseint () through?
ArithmeticException
ClassNotFoundException
NullPointerException
NumberFormatException
www.prolearninghub.com
11. What is output?
String s="abc";
Integer i=Integer.parseInt(s);
Runtime exception
Number format
exception
Arithmetic exception
Null pointer exception
www.prolearninghub.com
12. Exception can be rethrown?
No
Yes
In some case
None
www.prolearninghub.com
13. What will be the output of the
program?
public class Foo {
public static void main(String[] args) {try {
return;
} finally {
System.out.println( "Finally" );
Finally
Compilation fails.
The code runs with no
output.
An exception is thrown
at runtime.
www.prolearninghub.com
14. JDK 7 introduced a new
version of try statement known
as?
multiple try statement
try-with-multiple-catch
statement
Nested try statement
try-with-resources
statement
www.prolearninghub.com
15. If Super class method throws
an exception, then Subclass
overridden method.
Can throw the same
exception.
Can throw no
exception.
Can throw child class of
the exception thrown by
Super class method.
All of the Above.
www.prolearninghub.com
16. Inner class is a class:
Inside a class
Outside a class
Consecutive classes
None of mentioned
www.prolearninghub.com
17. Which is true about an
anonymous inner class?
class and implement
exactly one interface.
It can extend exactly one
class and can implement
multiple interfaces
It can extend exactly one
class or implement exactly
one interface
It can implement multiple
interfaces regardless of
whether it also extends a
class.
It can extend exactly one
www.prolearninghub.com
18. Which is true about a methodlocal inner class?
It must be marked
final.
It can be marked
abstract
It can be marked
public
It can be marked
static.
www.prolearninghub.com
19. Which statement is true about
a static nested class?
You must have a reference
to an instance of the
enclosing class in order to
instantiate it.
It does not have access to
nonstatic members of the
enclosing class
It's variables and methods
must be static
It must extend the
enclosing class
www.prolearninghub.com
20. Which constructs an
anonymous inner class instance?
Runnable r = new
Runnable() { };
Runnable r = new
Runnable(public void
run() { });
Runnable r = new Runnable
{ public void run(){}};
System.out.println(new
Runnable() {public
void run() { }});
www.prolearninghub.com
21. In Java, each thread has its own
--------, in which it runs ?
Main () method
JVM
Call Stack
Memory
www.prolearninghub.com
22. In Java, by default every thread
is given a --------- .
MIN-PRIORITY(0)
NORM-PRIORITY(5)
MAX-PRIORITY(10)
HIGH-PRIORITY(7)
www.prolearninghub.com
23. What will happen if we call run
() directly, without start() ?
Program will give a
compilation error.
Nothing will happen both
the methods are same.
Runtime error.
Thread won't be allocated a
new call stack, and start
running in the current call
stack.
www.prolearninghub.com
24. What is the name of the
method used to start a thread
execution?
Init();
Start();
Run();
Resume();
www.prolearninghub.com
25. Which cannot directly cause a
thread to stop executing?
Calling
the SetPriority() method
on a Thread object.
Calling
the wait() method on an
object.
Calling notify() method
on an object.
Calling read() method
on
an InputStream object.
www.prolearninghub.com
26. Which two of the following
methods are defined in class
Thread?
1. Start ();
2. Wait ();
3. Notify ();
4. Run ();
1 and 4
2 and 3
3 and 4
2 and 4
www.prolearninghub.com
27. Which of the following will
directly stop the execution of a
Thread?
Wait ();
Notify ();
Notifyall ();
Exits synchronized code
www.prolearninghub.com
28. Which method must be defined
by a class implementing
the java.lang.Runnable interface?
void run()
Public void run()
public void start()
void run(int priority)
www.prolearninghub.com
29. Which will contain the body of
the thread?
Run ();
Start ();
Stop ();
Main ();
www.prolearninghub.com
30. Which method registers a
thread in a thread scheduler?
Run ();
Construct ();
Start ();
Register ();
www.prolearninghub.com
31. Which of the following will not
directly cause a thread to stop?
Notify ()
Wait ()
InputStream ()
Sleep ()
www.prolearninghub.com
32. Which class or interface
defines
the wait(), notify(),and notifyAll()
methods?
Object
Thread
Runnable
class
www.prolearninghub.com
33. Two threads cannot enter into
a method side by side if the
methods are:
Static
Synchronized
Private
Package
www.prolearninghub.com
34. While using thread which of
the following is incorrect?
You invoke the run
method
You implement
runnable interface
You extend from
thread class
You call the start
method
www.prolearninghub.com
35. What is the name of method
which we use to schedule a
thread?
Init()
Start ()
Run ()
Resume ()
www.prolearninghub.com
36. What is a default priority of a
thread in java?
10
5
3
1
www.prolearninghub.com
37. A thread become not runnable
when
Its sleep method is
invoked
You implement
runnable interface
You extend from thread
class
You call the start
method
www.prolearninghub.com
38. What is default priority of a
newly created thread?
MIN-PERIORITY
MAX-PERIORITY
NORM-PERIORITY
None of these
www.prolearninghub.com
39. Which one of the following is a
static member of a thread
Current thread ()
Join ()
getName ()
Interrupt ()
www.prolearninghub.com
40. Select the valid state
transaction?
Ready to running
Ready to running
Waiting to running
Running to ready
www.prolearninghub.com
41. What is a dead thread in java?
A thread waiting for I/O
operation
A thread completed its
run method
A thread in sleep
None of these
www.prolearninghub.com
42. What allows the programmer
to destroy an object x?
x.delete()
x.finalize()
Runtime.getRuntime().
gc()
Only the garbage
collection system can
destroy an object.
www.prolearninghub.com
43. Identify the types of
multitasking?
Process based
Thread based
Both A and B
None of these
www.prolearninghub.com
43. Which data-type has highest
priority?
Integer
Float
Double
Long
www.prolearninghub.com
45. Which of these keywords are
used to define an abstract class?
abst
Abstract
Ab class
None of these
www.prolearninghub.com
46. Which one is not a abstract.
Thread
Class
List
AbstractList
www.prolearninghub.com
47. If a abstract class not define all
its function it’s called as -----.
Simple class
Super class
Static class
No class
www.prolearninghub.com
48. Which of these packages
contains abstract keyword?
Java.lang
java.util
Java.io
None of these
www.prolearninghub.com
49. Which of these events is
generated when the size os an
event is changed??
ComponentEvent
ContainerEvent
Both A and B
None of these
www.prolearninghub.com
50. Which event generated when a
component is added or removed.
ComponentEvent
ContainerEvent
FocusEvent
None of these
www.prolearninghub.com