wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Programming Quiz

Total questions: 15

Worksheet time: 9mins

Name
Class
Date
1.

Which component is responsible to optimize reusable byte code conversion to machine code?

a)

Class Loader

b)

Interpreter

c)

JIT Compiler

d)

Byte Code Verifier

2.

Predict the output: public static void main(String args[]) { int age; System.out.println(age); }

a)

0

b)

garbage value

c)

compilation error : variable needs to be initialized before use

d)

2147483647

3.

Which of these values can a boolean variable contain?

a)

true

b)

false

c)

0

d)

1

4.

identifiers cannot start with __________

a)

character

b)

digit

c)

_

d)

$

5.

Predict the output: public class Demo{ public static void main (string args[]){ int a =10,b=9; System.out.println(a

a)

true

b)

false

c)

10

d)

9

6.

public static void main(String args[]){ int i=10; if(i) System.out.println("Hello"); else System.out.println("Bye"); }

a)

Hello

b)

Compilation error: incompatible types: int cannot be converted to boolean

c)

Bye

d)

runtime error

7.

If an arithmetic expression contains variables of int , byte , and short data types , what will be the data type of its result?

a)

int

b)

byte

c)

float

d)

short

8.

public static void main(String[] args){ int num1 = 20; double num2 = 0; if(num1 >= 20) num2=1.5; if(num1<30) num2 = 2; System.out.println("Value of num2 is "+ num2); }

a)

Value of num2 is 2

b)

Value of num2 is 1.5

c)

Value of num2 is 2.0

d)

Value of num2 is 1.50

9.

Can we compare int variable with a Boolean variable?

a)

True

b)

False

10.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

11.

Which of the following is a comment in the Java language?

a)

/ comment /

b)

/* comment */

c)

/ comment */

d)

<-- comment -->

12.

Which of the following is the correct main() method signature in Java?

a)

public static void main (String [] args)

b)

public static void Main (String [] args)

c)

public static void main (string [] args)

d)

public static void main (String args)

13.

The import statement used in Java to access the Scanner class is:

a)

import java.Scanner;

b)

import java.util.Scanner;

c)

import java.package.Scanner

d)

import.java.util.Scanner;

14.

What is a class in object-oriented programming?

a)

A class is a template with data and methods

b)

A class is a package

c)

A class is the declared object in memory

d)

A class is a reference object in memory

15.

Which of the following is a reserved word in Java?

a)

export

b)

import

c)

input

d)

output