wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Practice Test

Total questions: 26

Worksheet time: 15mins

Name
Class
Date
1.

 

Find the output of the following code.

int Integer = 24;

char String = ‘I’;

System.out.print(Integer);

System.out.print(String);

a)

I

b)

24

c)

Compile time error

d)

24 I

2.

 

Find the output of the following program.

public class Solution{

public static void main(String[] args){

short x = 10;

x = x * 5;

System.out.print(x);

}

}

a)

50

b)

10

c)

Exception

d)

Compile time error

3.

 

Find the output of the following program.

public class Solution{

public static void main(String[] args){

byte x = 127;

x++;

x++;

System.out.print(x);

} }

a)

129

b)

128

c)

-127

d)

2

4.

Select the valid statement.

a)

char[] ch = new char(5)

b)

char[] ch = new char[5]

c)

char[] ch = new char()

d)

char[] ch = new char[]

5.

Select the valid statement to declare and initialize an array.

a)

int[] A = {}

b)

int[] A = {1, 2, 3}

c)

int[] A = (1, 2, 3)

d)

int[][] A = {1,2,3}

6.

Arrays in java are-

a)

Object references

b)

objects

c)

Primitive data type

d)

None

7.

 

When is the object created with new keyword?

a)

At run time

b)

At compile time

c)

Depends on the code

d)

None

8.

Identify the corrected definition of a package.

a)

A package is a collection of editing tools

b)

A package is a collection of classes

c)

A package is a collection of classes and interfaces

d)

A package is a collection of interfaces

9.

 

Identify the correct restriction on static methods.

They must access only static data

They can only call other static methods.

They cannot refer to this or super.

a)

I and II

b)

II and III

c)

Only III

d)

I, II and III

10.

Identify the keyword among the following that makes a variable belong to a class, rather than being defined for each instance of the class.

a)

final

b)

static

c)

volatile

d)

abstract

11.

 

Identify the output of the following program.

Public class Test{

Public static void main(String argos[]){

String str1 = “one”;

String str2 = “two”;

System.out.println(str1.concat(str2));

} }

a)

one

b)

two

c)

onetwo

d)

twoone

12.

Java was developed by Dennis Richie.

a)

Yes

b)

No

13.

Who invented Java Programming?

a)

Guido van Rossum

b)

James Gosling

c)

Dennis Ritchie

d)

Bjarne Stroustrup

14.

Which statement is true about Java?

a)

Java is a sequence-dependent programming language

b)

Java is a code dependent programming

c)

Java is a platform-dependent programming language

d)

Java is a platform-independent programming language

15.

Tell me name of 6th part of Harry Potter.

a)

Harry Potter and the Philosopher's Stone

b)

Harry Potter and the Goblet of Fire

c)

Harry Potter and the Half-Blood Prince

d)

Harry Potter and the Chamber of Secrets

16.

Look at this series: 12, 11, 13, 12, 14, 13, … What number should come next?

a)

10

b)

16

c)

13

d)

15

17.

Which of the following is not a Java features?

a)

Dynamic

b)

Architecture Neutral

c)

Use of pointers

d)

Object-oriented

18.

Look at this series: 2, 1, (1/2), (1/4), … What number should come next?

a)

(1/3)

b)

(1/8)

c)

(2/8)

d)

(1/16)

19.

Which word does NOT belong with the others?

a)

index

b)

glossary

c)

chapter

d)

book

20.

An interface with no fields or methods is known as a ______.

a)

Runnable Interface

b)

Marker Interface

c)

Abstract Interface

d)

CharSequence Interface

21.

Which of these classes are the direct subclasses of the Throwable class?

a)

RuntimeException and Error class

b)

Exception and VirtualMachineError class

c)

Error and Exception class

d)

IOException and VirtualMachineError class

22.

What do you mean by chained exceptions in Java?

a)

Exceptions occurred by the VirtualMachineError

b)

An exception caused by other exceptions

c)

Exceptions occur in chains with discarding the debugging information

d)

None of the above

23.

Which keyword is used for accessing the features of a package?

a)

package

b)

import

c)

extends

d)

export

24.

Multiple Inheritance is supported in java by "extends" keyword.

a)

Yes

b)

No

25.

Which of the following is a mutable class in java?

a)

java.lang.String

b)

java.lang.Byte

c)

java.lang.Short

d)

java.lang.StringBuilder

26.

Have you enjoyed??

a)

Yes

b)

No

c)

Not Sure