wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Comprog - (Review) - October 24, 2022

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

Which of the following is a LEGAL identifier?

a)

2ndScore 

b)

First-number

c)

_ratePerHour

d)

main

2.

Which of the following statement is a CORRECT?

a)

System.out.println("Hello);

b)

System.out.println("Hello");

c)

System.out.println("Hello")

d)

System.out.println(Hello);

3.

Which of the following statement is NOT true?

a)

Every Java program starts from a main method

b)

In Java, OK and ok are the same

c)

/* */ indicates a comment line

d)

static is a reserved word

4.

Who is the father of Java?

a)

James A. Gosling

b)

Jeffrey A. Gosling

c)

Jerry A. Gosling

d)

Joseph A. Gosling

5.

Which of the following is NOT a Java data type?

a)

String

b)

void

c)

boolean

d)

static

6.

Which of the following is the equivalent compound statement, x = x / 5;?

a)

x /= 5;

b)

x // 5;

c)

x =/ 5;

d)

xx / 5;

7.

Which of the following is a correct variable declaration?

a)

int x, y = 23;

b)

double p = 10%;

c)

String message = hello;

d)

char choice = “Y”;

8.

What is the output of the statement,

System.out.print(25 >= 15);

a)

25

b)

true

c)

false

d)

15

9.

Which of the following statement is INCORRECT?

a)

Integer.parseInt(output);

b)

Double.parseDouble(output);

c)

Float.parseFloat(output);

d)

String.parseString(output);

10.

Which of the following does NOT belong to the group?

a)

JOptionPane.INFO_MESSAGE;

b)

JOptionPane.ERROR_MESSAGE;

c)

JOptionPane.QUESTION_MESSAGE;

d)

JOptionPane.PLAIN_MESSAGE;

11.

What is the result of the logical expression,

(true || true) && false ?

a)

true

b)

false

12.

What is the output of the statement,                

System.out.print((double)(2 + 6 * 3)) ?

a)

20.0

b)

20

c)

24

d)

24.0

13.

Which of the following is a relational operator?

a)

||

b)

<>

c)

=

d)

!=

14.

Identify the output of the following code:

int grade = 90;

if(grade == 90)

System.out.print(“great”);

System.out.print(“  job”);

a)

great

b)

job

c)

great job

d)

greatjob

15.

Identify the output of the following code:

String section = “Divine”;

int grade = 11;

System.out.printf(“%d - %s”, grade, section);

a)

11 - Divine

b)

Grade 11 Divine

c)

Grade 11 - Divine

d)

Grade Divine  - 11

16.

Identify the output of the following code:

int number = 14;

if(number %2 == 0)

System.out.print(“Even”);

else

System.out.print(“Odd”);

a)

Even

b)

Odd

c)

Even

Odd

d)

EvenOdd

17.

Identify the output of the following code:

double rate = 40.0;

if(rate > 50.0)

System.out.println(rate * 2);

else if(rate > 40.0)

System.out.println(rate / 2);

else

System.out.println(rate – 2);

a)

80.0

b)

20.0

c)

38.0

d)

42.0

18.

Which of the following statements produces error?

a)

char c = (a > b) ? 10: 15;

b)

int x = (a % 2==0) ? 2 : 4;

c)

String y = (a == “Apple”) ? “fruit”: “vegetable”;

d)

char res = (a != b) ? ‘A’ : ‘B’;

19.

Identify the output of the following code:

int score = 5;

char gender = ‘F’;

if(score > 10 || gender == ‘M’)

System.out.print(“Good”);

if(score > 10 || gender == ‘F’)

System.out.print(“Great”);

a)

Good

b)

Great

c)

GoodGreat

d)

No output

20.

Identify the output of the following code:

int num1 = 30, num2 = 10;

int min = (num1 < num2) ? 30 : 10;

System.out.println(min);

a)

10

b)

30

c)

1030

d)

No output

21.

Which of the following is a logical operator?

a)

!!

b)

!

c)

!=

d)

<>

22.

Which is the alternative to switch in Java language?

a)

break, continue

b)

if, else

c)

do-while

d)

goto, exit

23.

A switch statement accepts ___ type of data as input.

a)

byte

b)

int

c)

long

d)

all of the choices

24.

Identify the output of the following code:

int numFruits = 37;

int choice = 37;

switch(choice) {

case numFruits: System.out.print("MANGO");

break;

default: System.out.println("APPLE");

}

a)

APPLE

b)

MANGO

c)

MANGOAPPLE

d)

APPLEMANGO

25.

Which of the following is INCORRECT?

a)

import java.util.Scanner;

b)

import javax.swing;

c)

import java.io.FileReader;

d)

import java.io.PrintWriter;