wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Exc_Thr_Col 1MCQ

Total questions: 50

Worksheet time: 3hrs 30mins

Name
Class
Date
1.
a)

{1=C, 2=JavaEE, 4=Python, 3=PHP}

b)

{1=C, 2=JavaSE, 3=Python, 4=PHP}

c)

{1=C, 2=JavaEE, 3=Python, 4=PHP}

d)

{1=C, 2=JavaSE,2=JavaEE, 3=Python, 4=PHP}

e)

NullPointerException

2.
a)

{null=null, a=null, b=JavaSE, c=PHP, d=Python}

b)

{a=null, b=JavaSE, c=PHP, d=Python}

c)

{b=JavaSE, c=PHP, d=Python}

d)

Compilation Fails

3.
a)

4

b)

5

c)

6

d)

12

4.
a)

[Computer, Network, Networks, Programming, Security]

b)

[Computer, Programming, Network, Networks, Programming, Security]

c)

[Computer, Programming, Computer, Networks, Network, Security]

d)

[Computer, Networks, Network, Programming, Security]

5.

 What will be the output of the  Java program?

a)

{0, 1, 3, 4}

b)

{0, 1, 2, 4}

c)

{0, 1, 2, 3, 4}

d)

{0, 0, 0, 3, 4}

6.

What will be output of given code

a)

a followed by concurrentModification Exception

b)

a b c

c)

a b

d)

a c

7.

Which interface does java.util.Hashtable implement?

a)

Java.util.Map

b)

Java.util.List

c)

Java.util.HashTable

d)

Java.util.Collection

8.

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?

a)

java.util.Map

b)

java.util.Set

c)

java.util.List

d)

java.util.Collection

9.

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

a)

java.util.HashSet

b)

java.util.LinkedHashSet

c)

java.util.List

d)

java.util.ArrayList

10.

The default capacity of a Vector is:

a)

10

b)

12

c)

8

d)

0

11.

The Comparable interface contains which called?

a)

toCompare

b)

compare

c)

compareTo

d)

compareWith

12.

What will be output of given code

a)

1 2 3

b)

1 followed by exception

c)

Compile time error

d)

run time error

13.
What is the underlying data structure of LinkedList?
a)
Resizable array
b)
Double LinkedList
c)
Single LinkedList
d)
HashTable
14.
Which cursor can be used to move in both forward and backward directions?
a)
Enumeration
b)
Iterator
c)
ListIterator
d)
None of the above
15.

Predict the output:

a)

Compile time error

b)

Run time error

c)

Java

Unix

d)

Java

Unix

Oracle

C++

Perl

16.

Predict the output:

a)

Hello from Parent

b)

Hello from Child

c)

Compilation Error

d)

None of the above

17.

Predict the output:

a)

Compile Time Error : Array size is negative

b)

Runtime Exception : Array size is negative

c)

0

d)

-0

18.

Predict the output:

a)

Java

PJP

b)

Compile time error

c)

Runtime Exception : IndexOutOfBoundsException

d)

None of the above

19.

Predict the output:

a)

10

11

b)

10

10

c)

11

11

d)

11

10

20.

What will be the results of running this code?

a)

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

b)

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

c)

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

21.

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?

a)

List Interface

b)

Set Interface

c)

Queue Interface

d)

Map Interface

22.

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?

a)

List Interface

b)

Set Interface

c)

Queue Interface

d)

Map Interface

23.

What distinguishes the LinkedHashSet class from the HashSet class in the Java Collections framework?

a)

LinkedHashSet maintains insertion order

b)

LinkedHashSet allows duplicate values

c)

LinkedHashSet uses a tree structure for storage

d)

LinkedHashSet provides faster access times

24.

If you need a data structure that can be accessed and modified by multiple threads safely, which class would you select?

a)

ArrayList Class

b)

Vector Class

c)

LinkedList Class

d)

HashSet Class

25.

If you need a collection that ensures a first-in-first-out (FIFO) behavior, which interface would be the best fit?

a)

Set Interface

b)

List Interface

c)

Map Interface

d)

Queue Interface

26.

What's the primary advantage of using the SortedSet Interface over the standard Set Interface?

a)

It allows duplicates

b)

It processes items in a FIFO manner

c)

It sorts items based on their natural order or a defined comparator

d)

It allows random access

27.
a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2

28.
a)

10

b)

12

c)

11

d)

Compilation Error

29.

If int y = 10 then find int z = (++y * (y++ + 5))

(a)  

30.

Evaluate the following expression if the value of x=2, y=3 and z=1.

v = x + ––z + y++ +y

(a)  

31.

How many ways a thread can be created in Java multithreading?

a)

1

b)

2

c)

5

d)

10

32.

What is the advantage of Exception Handling

a)

To avoid abnormal termination of a program

b)

To find out errors

c)

To Debug program

d)

None of these

33.

What is the parent class of All Exceptions in JAVA

a)

Throwable

b)

Exception

c)

Error

d)

Bug

34.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

35.

try block may or may not contains catch blocks

a)

True

b)

False

36.

What is the purpose of 'throw' keyword

a)

To Raise an exception explicityly

b)

To Raise an exception implicityly

c)

To create user defined exceptions

d)

To create custom exceptions

37.

What is an exception

a)

Error occurred during the execution of a program

b)

Bug occurred during the compile time of a program

c)

Simply an Error

d)

It is related to input values

38.

How to create our own exception

a)

using 'throw' keyword

b)

using 'throws' keyword

c)

using 'finally' keyword

d)

using 'throwable' keyword

39.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

40.

Which of these keywords is not a part of exception handling?

a)

try

b)

finally

c)

thrown

d)

catch

41.

java.lang.NullPointerException is a

a)

Error

b)

runtime exception

c)

Compile time exception

d)

None

42.

Choose the CORRECT exception


String department="JTMK";

Integer no=Integer.parseInt(department);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

43.

Choose an exception if attempt to divide number by zero


int number = 89 / 0;

System.out.println("The answer is " + number);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundException

44.

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.

a)

NumberFormatException

b)

NullPointerException

c)

ArrayIndexOutOfBoundsException

d)

InvalidStringException

45.

What are immediate child classes of Throwable

a)

Error

b)

Exception

c)

CheckedException

d)

UnCheckedException

46.

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

a)

Runtime

b)

Compile time

c)

either compile time or run time

d)

None of these

47.

class IT

{

static public void main(String...args)

{

String s=null;

System.out.println("length is:"+s.length());

}

}

a)

It throws NullPointerException

b)

it throws IOException

c)

It throws StringExeption

d)

output is 0

48.

public class Foo

{

public static void main(String[] args)

{

try

{

return;

}

finally

{

System.out.println( "Finally" );

}

}

}

a)

Finally

b)

Compilation fails.

c)

The code runs with no output

d)

An exception is thrown at runtime.

49.

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");

a)

finished

b)

runtime error.

c)

Compilation fails

d)

Exception.

50.

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");

}}

a)

Error Statement

b)

ECE

c)

Hello

d)

ECEHello