Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java, part I

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

Who invented Java?

a)

Ryan Gosling

b)

Bjarne Stroustrup

c)

James Gosling

d)

Guido van Rossum

2.

Is String a primitive data type?

a)

Yes

b)

No

c)

Both

3.

Which method to use to find length of a string?

a)

length()

b)

size()

c)

long()

d)

count()

4.

String x = "10";

String y = "20";

String z = x + y;

System.out.println(z);

Guess the output.

a)

1020

b)

10 20

c)

30

d)

"10 20"

5.

Choose most appropriate purpose of trim() method in String?

a)

to remove white spaces

b)

to get a substring of the string

c)

to cut String at desired index

d)

to remove extra white spaces from start and end of String

6.

What is the most appropriate way to check if two Strings are identical?

a)

string1 == string2

b)

string1.equals(string2)

c)

string1.same(string2)

d)

string1.equalsIgnorecase(string2)

7.

int[] myArray = {11, 22, 33, 44, 55};

which code is correct to print length of above int-array?

a)

System.out.println(int[].myArray.length());

b)

System.out.println(myArray.length);

c)

System.out.println(myArray.length());

d)

System.out.println(int[].myArray.size());

8.

Java was originally named:

a)

Coffee

b)

Oak

c)

New C++

d)

Duke

9.

What is the output?


int array[][] ={{9001, 2000, 1243), {77, 88, 99, 111}};

System.out.println(array[1][3]);

a)

1243

b)

99

c)

111

d)

Index out of bounds error

10.

Multiple inheritance allows a class to inherit characteristics and features from more than one abstract parent class. This allows a subclass to extend more than one superclass, in order to use the methods of each. Java supports multiple inheritance.

a)

True

b)

False

11.

This is a general structure a method.

a)

<Returnvalue type> <Method Name> (argument / s)

b)

<Modifier> < type> <Method Name> (parameter / s)

c)

public static void main (String[ ] args)

d)

<Method Name> (parameter)

12.

The difference between static and non static method is ....

a)

for non static method : user need to create object in a class to call a method.

b)

A method is to perform only specific task.

c)

There is no significant differences between static and non - static method.

d)

Both are bounded with a class.

13.

Explain JDK

a)

It stands for Java Development Kit

b)

It is the tool necessary to compile, document and package Java programs

c)

None of the above

d)

Both 1 and 2

14.

What is JVM

a)

It stands for Java Virtual Machine

b)

It is an abstract machine. It is specification that provides run-time environment in which java bytecode can be executed

c)

None of the above

d)

Both 1 and 2

15.

public is an

a)

access modifier

b)

keyword

c)

return type

d)

method

16.

constructors has no return type in Java

a)

True

b)

False

17.

Which of the following is available both in C++ and Java?

a)

friend

b)

try-catch-finally

c)

interface

d)

multiple inheritance

e)

public inheritance

18.

Which of the following access modifiers makes the member accessible from a class in the same package?

a)

private

b)

protected

c)

public

d)

default

19.

Assuming Point is a valid class, what would be the result of this code: Point p[] = new Point[10]; System.out.println(p[3].getX());

a)

0

b)

Null Pointer Exception

c)

-999

d)

Index Out of Bound Error

20.

Which are true about String?

a)

is a primitive type

b)

is a class

c)

is immutable

d)

can be instantiated without using constructors