WorksheetsJava Exc_Thr_Col 1MCQ
Total questions: 50
Worksheet time: 3hrs 30mins
{1=C, 2=JavaEE, 4=Python, 3=PHP}
{1=C, 2=JavaSE, 3=Python, 4=PHP}
{1=C, 2=JavaEE, 3=Python, 4=PHP}
{1=C, 2=JavaSE,2=JavaEE, 3=Python, 4=PHP}
NullPointerException
{null=null, a=null, b=JavaSE, c=PHP, d=Python}
{a=null, b=JavaSE, c=PHP, d=Python}
{b=JavaSE, c=PHP, d=Python}
Compilation Fails
4
5
6
12
[Computer, Network, Networks, Programming, Security]
[Computer, Programming, Network, Networks, Programming, Security]
[Computer, Programming, Computer, Networks, Network, Security]
[Computer, Networks, Network, Programming, Security]
What will be the output of the Java program?
{0, 1, 3, 4}
{0, 1, 2, 4}
{0, 1, 2, 3, 4}
{0, 0, 0, 3, 4}
What will be output of given code
a followed by concurrentModification Exception
a b c
a b
a c
Which interface does java.util.Hashtable implement?
Java.util.Map
Java.util.List
Java.util.HashTable
Java.util.Collection
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order.
Which interface provides that capability?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
The default capacity of a Vector is:
10
12
8
0
The Comparable interface contains which called?
toCompare
compare
compareTo
compareWith
What will be output of given code
1 2 3
1 followed by exception
Compile time error
run time error
Predict the output:
Compile time error
Run time error
Java
Unix
Java
Unix
Oracle
C++
Perl
Predict the output:
Hello from Parent
Hello from Child
Compilation Error
None of the above
Predict the output:
Compile Time Error : Array size is negative
Runtime Exception : Array size is negative
0
-0
Predict the output:
Java
PJP
Compile time error
Runtime Exception : IndexOutOfBoundsException
None of the above
Predict the output:
10
11
10
10
11
11
11
10
What will be the results of running this code?
Showing elements in forward direction
index:0 value: Jaguar
index:1 value:Porcshe
index:2 value:BMW
index:3 value: Ferrari
Showing elements in backward direction
index:3 value: BMW
index:2 value: Ferrari
index:1 value:Porsche
index:0 value:Jaguar
Showing elements in forward direction
index:1 value:Ferrari
index:2 value:Porcshe
index:3 value:BMW
index:4 value:Jaguar
Showing elements in backward direction
index:1 value:Jaguar
index:2 value:BMW
index:3 value:Porsche
index:4 value:Ferrari
Showing elements in forward direction
index:0 value:Ferrari
index:1 value:Porcshe
index:2 value:BMW
index:3 value:Jaguar
Showing elements in backward direction
index:3 value:Jaguar
index:2 value:BMW
index:1 value:Porsche
index:0 value:Ferrari
When designing an application to manage a restaurant's waiting list where customers are served based on their arrival, which interface would be best suited?
List Interface
Set Interface
Queue Interface
Map Interface
If you're building a system for online voting where each vote is unique, but the order in which votes are cast doesn't matter, which interface would be the best pick?
List Interface
Set Interface
Queue Interface
Map Interface
What distinguishes the LinkedHashSet class from the HashSet class in the Java Collections framework?
LinkedHashSet maintains insertion order
LinkedHashSet allows duplicate values
LinkedHashSet uses a tree structure for storage
LinkedHashSet provides faster access times
If you need a data structure that can be accessed and modified by multiple threads safely, which class would you select?
ArrayList Class
Vector Class
LinkedList Class
HashSet Class
If you need a collection that ensures a first-in-first-out (FIFO) behavior, which interface would be the best fit?
Set Interface
List Interface
Map Interface
Queue Interface
What's the primary advantage of using the SortedSet Interface over the standard Set Interface?
It allows duplicates
It processes items in a FIFO manner
It sorts items based on their natural order or a defined comparator
It allows random access
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
10
12
11
Compilation Error
If int y = 10 then find int z = (++y * (y++ + 5))
(a)
Evaluate the following expression if the value of x=2, y=3 and z=1.
v = x + ––z + y++ +y
(a)
How many ways a thread can be created in Java multithreading?
1
2
5
10
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
What is the parent class of All Exceptions in JAVA
Throwable
Exception
Error
Bug
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
try block may or may not contains catch blocks
True
False
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
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
How to create our own exception
using 'throw' keyword
using 'throws' keyword
using 'finally' keyword
using 'throwable' keyword
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Which of these keywords is not a part of exception handling?
try
finally
thrown
catch
java.lang.NullPointerException is a
Error
runtime exception
Compile time exception
None
Choose the CORRECT exception
String department="JTMK";
Integer no=Integer.parseInt(department);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundsException
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
class IT
{
static public void main(String...args)
{
int k=Integer.parseInt(args[0]);
System.out.println(k);
}
}
if args[0]="gec" then what type of exception is thrown by the above program.
NumberFormatException
NullPointerException
ArrayIndexOutOfBoundsException
InvalidStringException
What are immediate child classes of Throwable
Error
Exception
CheckedException
UnCheckedException
class Add
{
static public void main(String...args)
{
try
{
int a=10,b=0;
System.out.println(a/b);
}
catch(ArithmeticException ex)
{
System.out.println("Error:");
}
}
}
Above program throws an exception at
Runtime
Compile time
either compile time or run time
None of these
class IT
{
static public void main(String...args)
{
String s=null;
System.out.println("length is:"+s.length());
}
}
It throws NullPointerException
it throws IOException
It throws StringExeption
output is 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.
What is the output of the following Code:
public class Main
{
public static void main(String[] args) {
try {
System.out.println(0/0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println("ECE");
}
System.out.println("Hello");
}}
Error Statement
ECE
Hello
ECEHello
