wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Exception Handling Package Interface Test

Total questions: 81

Worksheet time: 3hrs 42mins

Name
Class
Date
1.

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

2.

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

a)

try

b)

catch

c)

finally

d)

throw

3.

try block may or may not contains catch blocks

a)

True

b)

False

4.

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

5.

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

6.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

7.

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

a)

try

b)

finally

c)

thrown

d)

catch

8.

Which of these class is highest in hierarchy in java

a)

java.lang.Exception

b)

java.lang.Error

c)

java.lang.Throwable

d)

java.lang.Object

9.

Choose the CORRECT exception


String department="JTMK";

Integer no=Integer.parseInt(department);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

10.

1. Which of these keywords must be used to monitor for exceptions?

a)

a) try

b)

b) finally

c)

c) throw

d)

d) catch

11.

2. Class at the top of exception class hierarchy?

a)

ArithmeticException

b)

Throwable

c)

Object

d)

Exception

12.

3. In which of the following package, Exception class exist?

a)

java.util

b)

java.io

c)

java.lang

d)

java.file

13.

4. Exception generated by try block is caught in ______ block?

a)

catch

b)

throw

c)

throws

d)

finally

14.

Exception and Error are direct subclasses of?

a)

.BaseException

b)

Throwable

c)

Object

d)

RuntimeException

15.

What block is always executed, independently of a exception being raised?

a)

throws

b)

finally

c)

catch

d)

throw

16.

What keyword is used to explicitly raise a exception?

a)

catch

b)

throw

c)

throws

d)

raise

17.

Exception is a class/interface/abstract class/other?

a)

Class

b)

Interface

c)

Abstract class

d)

Other

18.

What type of exception is thrown by parseInt() if it gets illegal data?

a)

ArithmeticException

b)

RunTimeException

c)

NumberFormatException

d)

NumberErro

19.

Which option is correct for creating a package named s3cs ?

a)

create package s3cs;

b)

package s3cs;

c)

define package 3cs;

d)

s3cs;

20.

To use a class or a package from the library which keyword is used

a)

include

b)

package

c)

import

d)

export

21.

A class member can be accessed only by a class in the same package. Which is the suitable access specifier?

a)

public

b)

default

c)

private

d)

protected

22.

A class member cannot be accessed by any other class inside or outside the package. Which is the suitable access specifier?

a)

private

b)

public

c)

default

d)

protected

23.

Which of the following help to access all the classes in the package p1?

a)

import p1;

b)

import p1.*;

c)

import p1.all;

d)

import p1.A;

24.

Which of the following help to use class Sample from package adm? (choose all appropriate options)

a)

import admSample;

b)

import adm.Sample;

c)

import Sample;

d)

import adm.*;

25.

Multiple inheritance in Java can be achieved using

a)

class and interface

b)

class

c)

interface

d)

package

26.

Which of the following is true about interface?

a)

Interface can contain abstract methods.

b)

A class implementing an interface should define all the methods in that interface.

c)

Interface is not used for creating objects.

d)

All of the above

27.

Choose the CORRECT mechanism of exception handling.

a)

try block --> catch block --> finally block

b)

try block --> catch block --> throws exception

c)

try block --> catch block --> finally --> throws exception

d)

try block --> throws exception--> catch block --> finally block

28.

output of the program

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

29.

output of the program

a)

Base::show() called

b)

Derived::show() called

c)

Compiler Error

d)

Runtime Error

30.

Output of following Java Program?

a)

Derived::show() called

b)

compile time error

c)

Base::show() called

d)

runtime error

31.

Predict the output of following Java program

a)

garbage value

b)

0

c)

compile time error

d)

runtime error

32.

output of the program

a)

Compile error

b)

values of obj1:

a = 11 b = 21

values of obj2:

a = 11 b = 21

c)

values of obj1:

a = 11 b = 21

values of obj2:

a = 10 b = 20

d)

values of obj1:

a = 11 b = 20

values of obj2:

a = 10 b = 21

e)

runtime error

33.

What is the output of the following JAVA program ?

a)

dogood : dogoodgood

b)

dogood : gooddogood

c)

dogood : dodogood

d)

dogood : dogood

34.

output of the program

a)

inside static block

a = 4

inside constructor

a = 11

b)

Compiler Error

c)

Run Time Error

d)

inside static block

a = 4

inside constructor

a = 5

e)

inside static block

a = 10

inside constructor

a = 11

35.

what is the output

a)

9.0 9.0

b)

9 9

c)

compile time error

d)

none

36.
a)

I am a Person

b)

I am a Student

c)

I am a Person I am a Student

d)

I am a Student I am a Person

37.

Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?

a)

Public

b)

Protected

c)

No Modifier

d)

All of the mentioned

38.

Which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?

a)

Public

b)

Protected

c)

Private

d)

No Modifier

39.

Which of the following is an incorrect statement about packages?

a)

Package defines a namespace in which classes are stored

b)

A package can contain other package within it

c)

Java uses file system directories to store packages

d)

A package can be renamed without renaming the directory in which the classes are stored

40.

For which purpose packages are used in Java?

a)

Categorizes data

b)

Organizing java classes into namespaces

c)

faster compilation

d)

None of These

41.

which package is imported implicitly?

a)

java.applet

b)

java.util

c)

java.lang

d)

java.io

42.

Math class is in ………package.

a)

java.io

b)

java.lang

c)

java.util

d)

java.applet

43.

By convention, java packages begin with ………………. letters while all the class names begin with an ………………… letter.

a)

uppercase, uppercase

b)

lowercase, lowercase

c)

uppercase, lowercase

d)

lowercase, uppercase

44.

A package is a collection of

a)

classes

b)

interfaces

c)

editing tools

d)

classes and interfaces

45.

What are the valid statements for static keyword in Java?

a)

We can have static block in a class.

b)

The static block in a class is executed every time an object of class is created.

c)

We can have static method implementations in interface.

d)

We can define static block inside a method.

46.

What is meaning * in import statement?

a)

To import selected classes from a package

b)

To import all classes from a package

c)

To import all classes from a package and multiply it

 

47.

It is compulsory to write main() function inside the class in Java.

a)

True

b)

False

48.

What will be the output of the following Java program?

a)

0

b)

2

c)

4

d)

None of these

49.

Which of these can be used to fully abstract a class from its implementation?

a)

Objects

b)

Packages

c)

Interfaces

d)

None of the Mentioned

50.

What is the output of this program?

a)

a=10

b)

a=20

c)

Compilation Error

d)

No Error, but no output

51.

What type of variable can be defined in an interface?

a)

public static

b)

private final

c)

public final

d)

static final

52.

What does an interface contain?

a)

Method definition

b)

Method declaration

c)

Method declaration and definition

d)

Method name

53.

Which of the following is correct way of implementing an interface salary by class manager?

a)

class manager extends salary {}

b)

class manager implements salary {}

c)

class manager imports salary {}

d)

None of the mentioned.

54.

What will be the output of the following Java program?

a)

0 1 2

b)

0 2 4

c)

0 0 4

d)

0 1 4

55.

Abstract class can have constructors and static methods?

a)

TRUE

b)

FALSE

c)

Abstract class can have constructors but can not have static methods.

d)

Abstract class can not have constructors but can have static methods.

56.

Which of these is not a correct statement?

a)

Every class containing abstract method must be declared abstract

b)

Abstract class defines only the structure of the class not its implementation

c)

Abstract class can be initiated by new operator

d)

Abstract class can be inherited

57.

The following Syntax is used for?


class Subclass-name extends Superclass-name

{

//methods and fields

}

a)

Polymorphism

b)

Encapsulation

c)

Inheritance

d)

None of the above

58.

What is an abstract method?

a)

An abstract method is any method in an abstract class.

b)

An abstract method is a method which cannot be inherited.

c)

An abstract method is one without a body that is declared with the reserved word abstract.

d)

n abstract method is a method in the child class that overrids a parent method.

59.

Predict the output :

a)

ArrayIndexOutOfBoundsException

b)

null

c)

0

d)

1

60.

An interface extends a class

a)

True

b)

interface implements a class

c)

Arithmetic Exception

d)

Compiler Error

61.

What will be the output?

a)

Nothing

b)

10

c)

Compile time error

d)

Runtime Exception

62.

Inside an interface, every method is public and abstract.

a)

TRUE

b)

FALSE

63.

The interface methods can be made final.

a)

TRUE

b)

FALSE

64.

What is the output?

a)

Compiler Error

b)

Happy Holi

c)

Run time Exception

d)

No error, No output

65.

The scope of an interface method implemented in a class (overridden) must be

a)

always private

b)

always less than the scope of interface method

c)

always more than the scope of interface method

d)

always public

66.

Object creation for Interface and abstract class..

a)

Cannot be created for both

b)

Can be created for Interface

c)

Can be created for Abstract class

d)

Can be created for both

67.

We prefer using interface when __________, and an abstract class when ______________.

a)

classes are not required, interfaces are not required

b)

we don't know any implementation, we know partial implementations

c)

we know every implementation, we know partial implementation

d)

we work on Java, we work on C++; It depends on language

68.
a)

10

0

5

b)

12

0

5

c)

10

5

0

d)

12

0

5

69.
a)

25

b)

24

c)

32

d)

33

70.

a)

0 2 4 6 8

b)

1 2 3 4 5

c)

0 1 2 3 4 5 6 7 8 9

d)

1 2 3 4 5 6 7 8 9 10

71.

super keyword in Java is used for ?

a)

to refer to immediate child class of a class.

b)

to refer to current class object.

c)

to refer to immediate parent class of a class.

d)

to refer to static member of parent class.

72.

Which is true ?

a)

"X extends Y" is correct if X and Y are either both classes or both interface.

b)

"X extends Y" is correct if and only if X is a interface and Y is a class.

c)

"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.

d)

"X extends Y" is correct if and only if X is a class and Y is an interface.

73.

If a class inheriting an abstract class does not define all of its function then it will be known as?

a)

abstract

b)

A simple class

c)

Static class

d)

None of the mentioned

74.

Which of the statement is false about an abstract class ?

a)

An abstract class is a class that contains one or more abstract methods.

b)

An abstract class cannot have normal method.

c)

An abstract class cannot be instantiated.

d)

An abstract class can be extended.

75.

Which of the following statement is true about an Interface ?

a)

Interface can not be nested inside another interface.

b)

Interface cannot implement a class.

c)

Interface can not extend one or more other interface.

d)

Methods inside Interface can be static, final, native or strictfp.

76.
a)

1,3 and 4

b)

1,2 and 4

c)

2,3 and 4

d)

1,2,3 and 4

77.

a)

1 and 2 only

b)

2,3 and 5

c)

3,4 and 5

d)

2 and 4

78.

which of the following are not java keywords

a)

double

b)

switch

c)

then

d)

instance of

79.

what is size of int in Java?

a)

2 bytes

b)

4 bytes

c)

6 bytes

d)

8 bytes

80.

Import java.lang.*;

class Rectangle

{

int l,b,a;

a=l*b;

void fun()

{

l=10;

b=20;

system.out.println("Area = ", a);

}

}

Identify errors in above program segment.

a)

Error in import line and Error in println line both

b)

Error in import line

c)

Error in println line

d)

No error at all

81.

To use a class or a package from the library which keyword is used

a)

include

b)

package

c)

import

d)

export