wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Strings

Total questions: 10

Worksheet time: 8mins

Name
Class
Date
1.

Strings in Java are _________.

a)

Mutable

b)

Immutable

2.

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

3.

What is the error in the following lines of code?

private String myMethod() {}

a)

String is not being returned.

b)

No value is being returned.

c)

There is no error.

4.

Create a String variable 'name' and put it equal to the value John Doe.

(a)  

5.

Which of the following will return the number of characters present in a String?

a)

length()

b)

length

c)

sizeOf()

d)

numberOfChars()

6.

What will be the output of the following line of code?

a)

HelloWorld

b)

Hello World

c)

"Hello World"

d)

"HelloWorld"

7.

What is the output of the following code?

a)

True

b)

False

c)

true

d)

false

8.

What is the output of following code?

a)

Llo World

b)

Hello World

c)

llo World

d)

llo world

9.

What is the output of the following lines of code?

a)

8

b)

r

c)

o

d)

IndexOutOfBoundsException in thread main

10.

What is the output of the following code?

a)

HELLO WORLD

b)

hello world

c)

"HELLO WORLD"

d)

Hello World