Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Quiz

Total questions: 30

Worksheet time: 22mins

Name
Class
Date
1.

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

a)

1

b)

2

c)

5

d)

10

2.

Which will contain the body of the thread in Java?

a)

Start()

b)

Run()

c)

Main()

d)

Execute()

3.

The life cycle of a thread in java is controlled by

a)

JRE

b)

JDK

c)

JVM

d)

None

4.

Which method is used to get current running thread object?

a)

runningThread()

b)

currentThread()

c)

runnableThread()

d)

None

5.

Thread priority in Java is?

a)

Integer

b)

Float

c)

Double

d)

Long

6.

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

}

}

a)

0

b)

1

c)

2

d)

3

7.

Q) Execution of a java thread begins on which method call?

a)

Start ()

b)

Run ()

c)

Execute ()

d)

Launch ()

8.

Thread is _____________process that can run independently

a)

heavyweight

b)

lightweight

c)

compaction

d)

compression

9.

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

a)

try

b)

catch

c)

finally

d)

throw

10.

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

11.

How to create our own exception

a)

using 'throw' keyword

b)

using 'throws' keyword

c)

using 'finally' keyword

d)

using 'throwable' keyword

12.

Choose the CORRECT exception


String department="JTMK";

Integer no=Integer.parseInt(department);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

13.

What will this print?

a)

There was an error

b)

1

c)

9

d)

0

14.

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.

15.

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.

16.

Which of the following is the incorrect way of creating a string in java?

a)

var hello string = "world"

b)

String hello = "World";

c)

String hello = new String("World");

d)

final static String hello = "World";

17.

Which of these is an incorrect statement?

a)

String objects are immutable, they cannot be changed

b)

String object can point to some other reference of String variable

c)

StringBuffer class is used to store string in a buffer for later use

d)

None of the mentioned

18.

Which of these class is superclass of String and StringBuffer class?

a)

java.util

b)

java.lang

c)

ArrayList

d)

None of the mentioned

19.

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

}

}

a)

ABC

b)

BCD

c)

CDA

d)

ABCD

20.

Choose correct purpose of indexOf() in String class.

a)

returns the index (the position) of the last occurrence of a specified text in a string

b)

returns the character of the first occurrence of a specified character in a string

c)

returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

d)

returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

21.

super keyword is used to access

a)

only subclass methods

b)

parent class variables and methods

c)

subclass variables and methods

d)

only parent class methods

22.

Which of the following is a valid declaration of an object of class Fun

a)

Fun obj=new Fun;

b)

obj=new Fun();

c)

Fun obj=new Fun();

d)

new Fun obj;

23.

Access modifiers are

a)

public

b)

Default

c)

private

d)

proteced

24.

which member of a class can be accessible by the class of another package?

a)

public

b)

private

c)

defualt

d)

protected

25.

LIst top level access modifiers

a)

private

b)

package-private

c)

both

d)

none

26.
  1. How many threads can a process contain?


a)

1

b)

2

c)

multiple

d)

none

27.
  1. Which is thread safe?

a)
  1. StringBuffer

b)
  1. StringBuilder

c)

All

d)

None

28.
  1. synchronized instance methods acquire lock on?


a)
  1. object

b)
  1. class

c)

All

d)

None

29.

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

30.

Using which of the following, multiple inheritance in Java can be implemented?

a)

Interfaces

b)

Multithreading

c)

Protected methods

d)

Private methods