wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA FINAL TEST 01

Total questions: 112

Worksheet time: 4hrs 44mins

Name
Class
Date
1.

Which of these packages contain classes and interfaces used for input & output operations of a program?

a)

java.util

b)

java.lang

c)

java.io

d)

all of the mentioned

2.

Which of these class is not a member class of java.io package?

a)

String

b)

StringReader

c)

Writer

d)

File

3.

Which of these classes is used for input and output operation when working with bytes?

a)

InputStream

b)

Reader

c)

Writer

d)

All of the mentioned

4.

Which of these method of InputStream is used to read integer representation of next available byte input?

a)

read()

b)

scanf()

c)

get()

d)

getInteger()

5.

Which of these class is used to read characters in a file?

a)

FileReader

b)

FileWriter

c)

FileInputStream

d)

InputStreamReader

6.

Which of these is a process of writing the state of an object to a byte stream?

a)

Serialization

b)

Externalization

c)

File Filtering

d)

All of the mentioned

7.

Which of these is method of ObjectOutputStream class used to write the object to output stream as required?

a)

Write()

b)

write()

c)

StreamWrite()

d)

writeObject()

8.

Which of these is method of ObjectIntputStream class used to read the object from input stream as required?

a)

read()

b)

Read()

c)

StreamRead()

d)

readObject()

9.

How an object can become serializable?

a)

If a class implements java.io.Serializable class

b)

If a class or any superclass implements java.io.Serializable interface

c)

Any object is serializable

d)

No object is serializable

10.

Serializaed object can be transferred via network.

a)

True

b)

False

11.

Difference between System.out.print() and System.out.println()?

a)

print() prints out to the current line and does not go onto a new line like println() does.

b)

They are the same and it is up to the user on which one is used.

c)

println() prints out to the current line and does not go onto a new line like print() does.

12.

Is Java a static language or dynamic?

a)

Static

b)

Dynamic

13.

int x = 1;

x += 3;

int y = 6;

x = y

System.out.println(x);

What is the console output from the code above?

a)

It would result in an error.

b)

The output would be the number 4.

c)

The output would be the number 6.

d)

The output would be the number 3

14.

int x = 40;

for (int i = 0; i < x; i++){

// Do stuff

}

Is this the correct way to write a for loop?

a)

True

b)

False

15.

Java does not support.

a)

Multiple Inheritance

b)

Single Inheritance

c)

Multilevel Inheritance

d)

Hierarchical Inheritance

16.

Scanner class in Java belongs to which package?

a)

io

b)

util

c)

lang

d)

net

17.

Which of the following is correct way of writing class name in Java?

a)

MyClass

b)

myclass

c)

MYclass

d)

MYCLASS

18.

Which of the following is correct way of writing function name in Java?

a)

myfunction( )

b)

myFunction( )

c)

MYFUNCTION( )

d)

MyFunction( )

19.

Package name in Java should be written in?

a)

Small letter

b)

Capital letters

20.

What is the correct way of creating object in Java?

a)

ClassName object_name;

b)

ClassName object_name = new ConstructorName( );

c)

ClassName new = object_name ConstructorName( );

d)

ClassName object_name = ConstructorName( );

21.

Which of the following is NOT used while writing main() function in Java?

a)

public

b)

static

c)

void

d)

private

22.

1. main() function is compulsory in Java.

2. Every program in Java should have at-least one class.

a)

Only 1 is true

b)

Only 2 is true

c)

Both are true

d)

Both are false

23.

Array is

a)

immutable

b)

mutable

c)

always contant

24.

Which of the following are built-in packages in Java? Select TWO correct answers.

a)

util

b)

stdio

c)

io

d)

out

25.

Which java package is used to create GUI application programs?

a)

java.lang

b)

java.awt

c)

java.io

26.

Which event is generated when clicking a Button?

a)

ActionEvent

b)

ClickEvent

c)

WindowEvent

27.

Which one of the following is not a swing GUI component?

a)

JFrame

b)

JLabel

c)

Button

d)

JTextField

28.

Which of one of the following package does not contain GUI components?

a)

java.applet

b)

java.awt

c)

javax.swing

d)

java.io

29.

The statement JFrame myFrame = new JFrame(); creates a JFrame that is _______.

a)

invisible and has no title

b)

invisible and has a title

c)

visible and has no title

d)

visible and has a title

30.

Window created in a java program can be made to show using the method

a)

display()

b)

setVisible()

c)

focus()

31.

How would you change the text of a label to the text contained by an integer named num;

a)

label.setText(num);

b)

label.updateText(num);

c)

label.setTest("num");

d)

label.setText(num+ "");

32.

Math class is a part of Java.________ package

a)

io

b)

util

c)

lang

33.

what will be the output of Math.sqrt(-4.0)

a)

2

b)

-2

c)

NaN

34.

What will be the return value of Math.pow(2.0,3.0)

a)

8.0

b)

8

c)

NaN

35.

__________ function returns the magnitude of the number without the sign

a)

Math.round

b)

Math.floor

c)

Math.abs

36.

The return value for Math.round(-51.2) is

a)

-51

b)

-50

c)

-52

37.

Math.ceil() will always return _____ data type

a)

integer

b)

float

c)

double

38.

The output of the function Math.ceil(-31.987)

a)

-31.0

b)

-32.0

c)

-30.0

39.

The output of Math.floor(36.987) is

a)

36

b)

37

c)

35

40.

The output of the function Math.floor(-0.9)

a)

1

b)

0

c)

-1

41.

Math.max(-43,-41) will return

a)

-43

b)

-41

c)

NaN

42.

extends keyword is used in java for...?

a)

Inheritance

b)

Interfaces

c)

Copying a class

d)

No answer

43.

Re-usability is achieved with.........

a)

interface

b)

object

c)

class

44.
Which of the following statements are true about arrays in Java? Select all that apply.
a)
Stores homogeneous data.
b)
Size cannot be changed during runtime.
c)
Can store only user defined objects.
d)
Array index starts at 1.
45.

Which of the below are reserved keyword in Java?

a)

Array

b)

goto

c)

null

d)

None of the above

46.

What are the valid statements for static keyword in Java?

a)

We can have static block in a class.

b)

The static block in a class is executed every time an object of class is created.

c)

We can have static method implementations in interface.

d)

We can define static block inside a method.

47.

Which of the following is not a Java features?

a)

Dynamic

b)

Architecture Neutral

c)

Use of pointers

d)

Object-oriented

48.

which of the following is wrapper class in java

a)

Float

b)

Integer

c)

Double

d)

all of above

49.

which one of the following is a legal decelration of a two- dimensional array of integers

a)

int[] a[] = new int[5][];

b)

int[5][5] a = new int[][];

c)

int a = new int[5,5];

d)

int[][] a = new int[][5];

50.

which interface needs to be implemented in order to make an object seralized

a)

clonnable

b)

remote

c)

seralizable

d)

none of the above

51.

which of this class is used by character streams for reading data from buffer

a)

BufferReader

b)

InputStreamReader

c)

FileReader

d)

FileInputStream

52.

What index value is used to locate the last element in the nums ArrayList?

a)

nums.size()-1

b)

nums.length()-1

c)

nums.size()

d)

nums.length

53.
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
a)
 0, 1, 2, 3
b)
 1, 2, 3, 4
c)
2, 4, 6, 8
d)
 0, 2, 4, 6
54.

For the array:

int stats[3];

What is the range of the index?

a)

0 to 3

b)

0 to 2

c)

1 to 3

d)

0 to 4

55.

int [] nums = {2, 3, 5, 8, 9, 11};

How would you access the fourth element in nums?

a)

nums[4]

b)

nums[3]

c)

nums(4)

d)

nums(3)

56.
Which of the following statements outputs the fifth value in the quizzes array?
a)
System.out.println(quizzes[5]);
b)
quizzes[4];
c)
quizzes[5];
d)
System.out.println(quizzes[4]);
57.
Index values of an array range from ______________.
a)
0 to length – 1
b)
1 to length
c)
0 to length
d)
0 to length + 1
58.
Create an array of 12 strings called months.
a)
String[] months = new String[12];
b)
String months = new String[12];
c)
String[] months = new String[];
d)
String[12] months = new String[];
59.
Given the following method, what would test return if
a = {0, 2, 3, 4} and v = 1?
a)
-1
b)
0
c)
1
d)
2
60.
Given the following method, what would test return if
a = {0, 2, 3, 4} and v = 3?
a)
0
b)
1
c)
2
d)
-1
61.
Given the following method, what would test return if
a = {0, 2, 3, 4} and v = 2?
a)
0
b)
1
c)
2
d)
-1
62.
What value is at index 1 in this array?  String[] names = {"Mack", "Dennis", "Dee", "Charlie"};
a)
Mack
b)
Dennis
c)
Dee
d)
Charlie
63.
True or False:  An array can be store different types of data (like store both doubles and ints).
a)
True
b)
False
64.
What is the correct way to create an array with these three numbers: 12  8  15
a)
int[] = {12, 8, 15};
b)
int[] nums = {12  8  15};
c)
int[] nums = {12, 8, 15}
d)
int[] nums = {12, 8, 15};
65.
A variable that holds a whole number
a)
String
b)
boolean
c)
int
d)
float
66.

A variable that holds words

a)

String

b)

boolean

c)

int

d)

float

e)

A dictionary

67.

A variable that holds true or false

a)

String

b)

boolean

c)

int

d)

float

e)

Alex Trebek

68.

Name the data type: 1.0

a)

double

b)

int

c)

char

d)

boolean

69.

Name the data type: "true"

a)

boolean

b)

char

c)

String

d)

double

70.

Name the data type: false

a)

String

b)

boolean

c)

int

d)

None of the above

71.

What data type would you use for storing the number of students in a class?

a)

boolean

b)

String

c)

double

d)

int

72.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

73.

Describe method.

a)

A component of a program in a big program.

b)

A program to perform a specific task.

c)

A component of a program written to perform a specific task.

d)

A variable that use to read an input.

74.

There two (2) types of method which are

a)

return

b)

Standard library

c)

User defined

d)

non-return

75.

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)

76.

This is an example of a non-return method.

a)

True

b)

False

77.

In which line is representing the meaning of Standard library method.

a)

Line 2

b)

Line 8

c)

Line 13

d)

Line 10

78.

Identify the line with syntax error.

a)

Line 8 and Line 15

b)

Line 10 only

c)

Line 6, Line 8, Line 10

d)

Line 8, Line 11 and Line 15

79.

Identify and fix the syntax error.

a)

Mismatched of the argument and parameter.

Fix with :- call.Display(name,age);

b)

Wrong name of the class to declare the method call object.

Fix with :- Greeting call = new Greeting( );

c)

Wrong type of return type method.

Fix with :- int Display (int number, String member);

d)

Wrong method's name in calling the method.

Fix with :- call.Greeting(name,age);

80.

This program is consist with syntax error. Identify the reason and fix the error with the most suitable answer.

a)

Mismatched with data type of radius and height.

FIx with :- char radius, height;

b)

Mismatched with data type of r and h in method.

FIx with :- int r, h;

c)

Mismatched with variable name of radius and height.

FIx with :- double r, h;

d)

Mismatched with data type of radius and height.

FIx with :- double radius, height;

81.

How many stars are printed?

a)

7

b)

3

c)

4

d)

5

e)

Infinite Loop

82.

In total, how many times is the inner loop executed?

a)

5

b)

10

c)

15

d)

50

e)

Infinite Loop

83.

How many times does the loop print a *

a)

40

b)

20

c)

24

d)

30

e)

Infinite Loop

84.

What does the following code print?

a)

A rectangle of 8 rows with 5 stars per row

b)

A rectangle of 8 rows with 4 stars per row

c)

A rectangle of 6 rows with 5 stars per row

d)

A rectangle of 6 rows with 4 stars per row

e)

Infinite Looo

85.

What does the following code print?

a)

A rectangle of 9 rows with 5 stars per row

b)

A rectangle of 6 rows with 6 stars per row

c)

A rectangle of 7 rows with 5 stars per row

d)

A rectangle of 7 rows with 6 stars per row

e)

Infinite Loop

86.

What does the following code print?

a)

5 6 7 8 9

b)

4 5 6 7 8 9 10 11 12

c)

3 5 7 9 11

d)

3 4 5 6 7 8 9 10 11 12

87.

How many times does the following method print a *?

a)

9

b)

6

c)

7

d)

10

88.
True/False
If a loop condition is never satisfied then the loop does not execute.
a)
True
b)
False
89.
a)

1 2 4 8 16 32 64

b)

1 2 4 8 16 32

c)

2 4 8 16 32 64

d)

2 4 8 16 32

e)

4 8 16 32 64

90.
a)

200 66 22 7 2

b)

66 22 7 2

c)

200 66 22 2

d)

200 66 22

e)

7

91.
a)

10

b)

15

c)

17

d)

22

e)

25

92.

2

a)

5

b)

7

c)

9

d)

13

e)

20

93.
a)

-1 0 2 5

b)

-1 0 3 7

c)

-1 1 4 8

d)

0 2 5 9

e)

0 1 3 7

94.
a)

0.0

b)

-4.0

c)

5

d)

The program will end successfully, but nothing will be printed.

e)

Nothing will be printed. Run-time error: ArithmeticException.

95.

Which data type gets returned from length() method in String class?

a)

double

b)

String

c)

int

d)

number

96.

String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


What is the correct way to find the length of "txt" string?

a)

int len = length(txt);

b)

float len = txt.length();

c)

int len = txt.length();

d)

double len = length(txt);

97.

Which is correct method to convert String into uppercase

a)

changeUpperCase()

b)

convertUpperCase()

c)

toUpper()

d)

toUpperCase()

98.

String txt = "Hello World";

System.out.println(txt.toUpperCase());


Choose the correct output.

a)

"HELLO WORLD"

b)

HELLO WORLD

c)

Hello world

d)

Hello World

99.

Choose correct purpose of indexOf() in String class.

a)

returns the index (the position) of the last occurrence of a specified text in a string

b)

returns the character of the first occurrence of a specified character in a string

c)

returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

d)

returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

100.

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"

101.

What will be the output of below code?


String statement = "Outfit of the day";

System.out.println(statement.Substring(3,6));

a)

it of

b)

tfit

c)

fit

d)

FIT

102.

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

103.

What is the return type of equalsIgnorecase() method?

a)

int

b)

String

c)

char

d)

boolean

104.

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)

105.

What is the correct relation between length and last-index of array?

a)

last-index is always 1 more than the length

b)

last-index is 1 less than the length (but not always)

c)

last-index is always 1 less than the length

d)

last-index is always equal to the length

106.
String word = "A few good men";
What is word.length()?
a)
14
b)
15
c)
13
107.
String word = "A few good men";
What is word.charAt(7) ?
a)
o
b)
g
c)
7
d)
good men
108.
String word = "A few good men";
What is word.startsWith("A few") ?
a)
true
b)
false
109.

String word = "A few good men";

What is word.indexOf(“f”)?

a)

2

b)

0

c)

1

d)

3

110.
String word = "A few good men";
What is word.substring(3, 7) ?
a)
ew g
b)
ew go
c)
few
d)
few[space]
111.

Consider the given code. What would be the display on the screen?

a)

Class A

b)

Class B

c)

Class C

d)

Compile error

112.
What is the difference between a class and an object?
a)
A class is a blueprint to make an object
b)
An object is a blueprint to make a class
c)
A blueprint is an object to make a class
d)
Blueprint class is an object make a