WorksheetsJava Quiz
Total questions: 30
Worksheet time: 22mins
How many ways a thread can be created in Java multithreading?
1
2
5
10
Which will contain the body of the thread in Java?
Start()
Run()
Main()
Execute()
The life cycle of a thread in java is controlled by
JRE
JDK
JVM
None
Which method is used to get current running thread object?
runningThread()
currentThread()
runnableThread()
None
Thread priority in Java is?
Integer
Float
Double
Long
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();
}
}
0
1
2
3
Q) Execution of a java thread begins on which method call?
Start ()
Run ()
Execute ()
Launch ()
Thread is _____________process that can run independently
heavyweight
lightweight
compaction
compression
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
What is the purpose of 'throw' keyword
To Raise an exception explicityly
To Raise an exception implicityly
To create user defined exceptions
To create custom exceptions
How to create our own exception
using 'throw' keyword
using 'throws' keyword
using 'finally' keyword
using 'throwable' keyword
Choose the CORRECT exception
String department="JTMK";
Integer no=Integer.parseInt(department);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundsException
What will this print?
There was an error
1
9
0
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.
What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
finished
runtime error.
Compilation fails
Exception.
Which of the following is the incorrect way of creating a string in java?
var hello string = "world"
String hello = "World";
String hello = new String("World");
final static String hello = "World";
Which of these is an incorrect statement?
String objects are immutable, they cannot be changed
String object can point to some other reference of String variable
StringBuffer class is used to store string in a buffer for later use
None of the mentioned
Which of these class is superclass of String and StringBuffer class?
java.util
java.lang
ArrayList
None of the mentioned
What is the output of this program?
class String_demo {
public static void main(String args[]){
int ascii[] = { 65, 66, 67, 68};
String s = new String(ascii, 1, 3);
System.out.println(s);
}
}
ABC
BCD
CDA
ABCD
Choose correct purpose of indexOf() in String class.
returns the index (the position) of the last occurrence of a specified text in a string
returns the character of the first occurrence of a specified character in a string
returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)
returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)
super keyword is used to access
only subclass methods
parent class variables and methods
subclass variables and methods
only parent class methods
Which of the following is a valid declaration of an object of class Fun
Fun obj=new Fun;
obj=new Fun();
Fun obj=new Fun();
new Fun obj;
Access modifiers are
public
Default
private
proteced
which member of a class can be accessible by the class of another package?
public
private
defualt
protected
LIst top level access modifiers
private
package-private
both
none
How many threads can a process contain?
1
2
multiple
none
Which is thread safe?
StringBuffer
StringBuilder
All
None
synchronized instance methods acquire lock on?
object
class
All
None
Which of these can be used to fully abstract a class from its implementation?
Objects
Packages
Interfaces
None of the Mentioned
Using which of the following, multiple inheritance in Java can be implemented?
Interfaces
Multithreading
Protected methods
Private methods
