Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA BASIC 3

Total questions: 35

Worksheet time: 50mins

Name
Class
Date
1.

In java programming

a)

There must be at least two variables declared

b)

All of the value must be integer

c)

There must be a method called "main"

d)

There must be two private classes

2.

Choose the appropriate data type for this value: 5.5

a)

int

b)

double

c)

boolean

d)

string

3.

If you want your condition to depend upon two conditions BOTH being true. What is the proper notation to put between the two Boolean statements

a)

!

b)

!!

c)

&&

d)

>

4.

Which of the following is not a Java keyword

a)

Integer

b)

int

c)

public

d)

static

5.

Choose the appropriate data type for this field isSwimmer

a)

int

b)

String

c)

boolean

d)

object

6.

What is the output of

System.out.println("Hey");

System.out.println("World");

?

a)

Hey

World

_

b)

Hey

World_

c)

Hey World_

d)

HeyWorld_

7.

What is the output of

System.out.print("Hey");

System.out.print("World");

?

a)

Hey World_

b)

Hey

World_

c)

HeyWorld_

d)

Hey

World

_

8.

What is the output of

System.out.print("This");

System.out.println("That");

?

a)

ThisThat_

b)

This

That_

c)

This

That

_

d)

ThisThat

_

9.

Choose the right statement

a)

System.out.println(Abc)

b)

System,out,println(Abc)

c)

System.out.println("Abc")

d)

System,out,println("Abc"):

e)

System.out.println("Abc");

10.

How do you print "Hello" in Java?

a)

print "Hello";

b)

System.print("Hello");

c)

System out println("Hello");

d)

System.out.print("Hello");

11.

What is Java documentation?

a)

A textbook that teaches you Java syntax

b)

Line comments that tell you what a line of a program does

c)

A document that provides information about a class, such as the methods it has

d)

A journal of bugs and bug fixes in each version of your program

12.

What do you call the first line of a method that declares a method?

a)

method call

b)

the title

c)

method signature

d)

method parameters

13.

What does an int type variable store?

a)

A whole number

b)

A decimal point number

c)

A true or false value

d)

Text

14.

What does a double type variable hold?

a)

A whole number

b)

A decimal point number

c)

Text

d)

A true or false value

15.

What does a boolean type variable hold?

a)

A whole number

b)

A decimal point number

c)

Text

d)

A true or false value

16.

What does a String type variable hold?

a)

A whole number

b)

A decimal point number

c)

Text

d)

A true or false value

17.

What do you call a named block of statements?

a)

class

b)

method

c)

object

d)

variable

18.

With what method does the execution of a program start?

a)

main

b)

static

c)

public

d)

start

19.

What is the correct method signature for the main method?

a)

public void main(String[] args)

b)

public void main(String args)

c)

public void static main(String args)

d)

public static void main(String[] args)

20.

What is the return type of the method with the signature:

public boolean isTired()

a)

none

b)

boolean

c)

unspecified

d)

static

21.

What punctuation do you use to group related statements?

a)

semicolon ;

b)

curly braces { }

c)

brackets [ ]

d)

parentheses ( )

22.

What punctuation do you use to indicate the end of a statement?

a)

semicolon ;

b)

curly braces { }

c)

brackets [ ]

d)

parentheses ( )

23.

What would result in a syntax error?

a)

System.out.print("hi");

b)

System.out.println("hi");

c)

System.out.print("hi);

d)

System.out.print("hijhhj");

24.
a)

A

b)

B

c)

C

d)

D

e)

E

25.
a)

-5

b)

0

c)

13

d)

-1

e)

12

26.
a)

11

b)

12

c)

5

d)

9

e)

-4

27.

Consider the following code segment:

Line 1: int a = 10;

Line 2: double b = 10.7;

Line 3: double c = a + b;

Line 4: int d = a + c;

Line 5: System.out.println(c + " " + d);


What will be output as a result of executing the code segment?

a)

20 20

b)

20.0 30

c)

20.7 31

d)

20.7 30.7

e)

Nothing will be printed because of a compile-time error.

28.

Consider the following code segment:

Line 1: int a = 10;

Line 2: double b = 10.7;

Line 3: int d = a + b;


Line 3 will not compile in the code segment above. With which of the following statements could we replace this line so that is compiles?


I. int d = (int) a + b;

II. int d = (int) (a + b);

III. int d = a + (int) b;

a)

I

b)

II

c)

III

d)

I and III

e)

II and III

29.

Assume that x, y, and z have been declared as follows:


boolean x = true;

boolean y = false;

boolean z = true;


Which of the following expressions evaluates to true?

a)

x && y && z

b)

x && y || z && y

c)

!(x && y) || z

d)

!(x || y) && z

e)

x && y || !z

30.

Similar to variables but have the same value throughout the program

a)

Constants

b)

Variables

c)

Private

d)

Public

31.

Begins an end of the line comment; compiler knows to ignore these comments

a)

/** **/

b)

/

c)

//**

d)

//

32.

Occur when the program compiles and executes but the output is not what you wanted/expected

a)

Logic errors

b)

Runtime errors

c)

Syntax errors

33.

Grammar errors

a)

Logic error

b)

Syntax error

c)

Runtime error

34.

Error that occurs while the program is running

a)

Runtime error

b)

Logic error

c)

Syntax error

35.

Executes the program file

a)

Class

b)

Main Method

c)

Package

d)

Compiler