wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java

Total questions: 100

Worksheet time: 3570secs

Name
Class
Date
1.
Which type of data is used to enter the value ("Welcome")?
a)
Text
b)
Characters
c)
String
d)
Boolean
2.
Which type of data is used to enter the value (1234.5)?
a)
Integer
b)
Double 
c)
Char
d)
Void
3.
When we want to print in Java, we use the code ......
a)
system.out.print();
b)
System.out.println();
c)
System.Out.Printf();
d)
System.out.show();
4.

Java was originally named:

a)

Coffee

b)

Oak

c)

New C++

d)

Duke

5.

Who invented Java?

a)

James Gosling

b)

Sergey Brin

c)

Steve Jobs

d)

Bill Gates

e)

Tim Berners-Lee

6.

_________ operator returns the remainder after division

a)

+

b)

/

c)

%

d)

*

7.

Operator used to access the members of a class /package

a)

(.) Dot

b)

(,) Comma

8.

Java is

a)

platform dependent

b)

platform indeprndent

9.

Java programs ________________

a)

are only compiled

b)

are only compiled not interpreted

c)

are only interpreted

d)

are both compiled and interpreted

10.

In Java, execution starts from ___________ function.

a)

get()

b)

main()

c)

java()

d)

display()

11.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

12.

What's the value of below?


int i=5;

System.out.println(i++);

System.out.println(i);

System.out.println(++i);

a)

5

6

7

b)

6

6

7

c)

6

7

8

d)

5

5

6

13.

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

14.

Which statement below is the correct way to retrieve the first element in the nums ArrayList?

a)

nums.get(0)

b)

nums[0]

c)

nums(0)

d)

nums[1]

15.
How do you get the number of elements in an ArrayList called "list" in Java?
a)
list.size();
b)
list.count();
c)
list.length();
d)
list.getSize();
16.

Identify the error that exist in this method program:-

a)

Wrong use of return method type

b)

variable extra was unknown.

c)

doble is not one of the data type

d)

A wrong use of hour data type.

17.
_________________ is a collection of elements used to store the same type of data.
a)
Array
b)
Switch
c)
Case
d)
Loop
18.
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
19.
A variable that holds a whole number
a)
String
b)
boolean
c)
int
d)
float
20.

What is the output of this program?

a)

0

b)

1

c)

120

d)

None of the above

21.

How many stars are printed?

a)

7

b)

3

c)

4

d)

5

e)

Infinite Loop

22.

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

a)

5

b)

10

c)

15

d)

50

e)

Infinite Loop

23.

It is an optional statement used to describe what a program or a line of program is doing.

a)

tag

b)

command

c)

code

d)

comment

24.

Which of the followings is Java code that starts from the main() method as a mandatory part of every program

a)

public void static main(String args [])

b)

public void main static (args[] String)

c)

public static void main (String args[])

d)

public static void main [String [] Args]

25.

A Java statement is one or more lines of code terminated by a semicolon. True or False?

a)

False

b)

True

26.

A Java block is formed by enclosing statements by open and close parentheses. True or False?

a)

True

b)

False

27.

What is the advantage of Exception Handling

a)

To avoid abnormal termination of a program

b)

To find out errors

c)

To Debug program

d)

None of these

28.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

29.

try block may or may not contains catch blocks

a)

True

b)

False

30.

What is an exception

a)

Error occurred during the execution of a program

b)

Bug occurred during the compile time of a program

c)

Simply an Error

d)

It is related to input values

31.

int len = "jump it!".length();


What is the value of len?

a)

8

b)

7

c)

9

d)

6

e)

This code does not compile.

32.

String s1 = "hello";

String s2 = new String("hello");

if (s1 == s2) System.out.print("Hey");

else System.out.print("Yo");


What is the output?

a)

Hey

b)

Yo

c)

There is no output.

d)

This code will not compile.

33.

Generally string is a sequence of characters, But in java, string is an _______.

a)

Object

b)

Class

c)

Package

d)

None of the above

34.

Which inheritance is not supported in java?

a)

Multiple

b)

Multilevel inheritance

c)

Hybrid

d)

Java supports all of the above

35.

Which data type is not supported by ArrayList?

a)

Integer

b)

String

c)

double

d)

Boolean

36.

What is an instance of a class?

a)

Class

b)

Object

c)

Reference

d)

Primitive

37.

Is "X" printed?

a)

YES

b)

NO

38.

Which one of the following is a valid statement?

a)

char[] c = new char();

b)

char[] c = new char[5];

c)

char[] c = new char(4);

d)

char[] c = new char[];

39.

Which component is used to compile, debug and execute java program?

a)

JVM

b)

JDK

c)

JRE

d)

JIT

40.

Which component is responsible for converting bytecode into machine specific code

a)

JVM

b)

JDK

c)

JRE

d)

JIT

41.

Which component is responsible to run java program

a)

JVM

b)

JDK

c)

JRE

d)

JIT

42.

Java is ______________________

a)

Object based

b)

Object Oriented

c)

fully object oriented

d)

procedural

43.

--------- is a symbol, that operates on operands and produce a result

a)

operands

b)

variables

c)

operators

d)

Ternary

44.

What is the result of 13<=13 ?

a)

True

b)

False

c)

Both true and false

d)

None

45.

Syntax for main method

a)

void main()

b)

void main(String[] args)

c)

public static void main(String[] args)

d)

public main(String[] args)

46.

Which of these are selection statements in Java?

a)

if()

b)

for

c)

continue

d)

break

47.

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

a)

for

b)

while

c)

do..while

d)

None of the above

48.

What will be the output of the following Java program?

class selection_statements

{

public static void main(String args[])

{

int var1 = 5;

int var2 = 6;

if ((var2 = 1) == var1)

System.out.print(var2);

else

System.out.print(++var2);

} }

a)

1

b)

2

c)

3

d)

4

49.

Which of the statement test only for equality?

a)

if

b)

switch

c)

if & switch

d)

None of the above

50.

What will be the output of the following program.

class WeekDays

{

public static void main(String s[])

{

int day = 4;

switch(day)

{

case 1:

System.out.println("Monday");

case 2:

System.out.println("Tuesday");

case 3:

System.out.println("Wednesday");

case 4:

System.out.println("Thursday");

case 5:

System.out.println("Friday");

default:

System.out.println("Weekend");

break;

}

}

}

a)

Thursday

b)

Compilation Error

c)

Thursday

Friday

Weekend

d)

Runtime error

51.

What will be the output of the following program.

class WeekDays

{

public static void main(String s[])

{

int day = 7;


switch(day)

{

case 1:

System.out.println("Monday");

case 2:

System.out.println("Tuesday");

case 3:

System.out.println("Wednesday");

case 4:

System.out.println("Thursday");

case 5:

System.out.println("Friday");

}

}

}

a)

No Output

b)

Compilation Error

c)

Sunday

d)

Runtime error

52.

What will the following code segment print?

System.out.println(17 % 3);

(a)  

53.

What will be the value in variable x after this code segment is executed?

double x = 5.0 + 2;

a)

7

b)

7.0

c)

There will be a runtime error

d)

There will be a syntax error

e)

5.02

54.

Find the output

class Test {

public static void main(String args[]) {

int arr[2];

System.out.println(arr[0]);

System.out.println(arr[1]);

}

}

a)

Compile error

b)

Exception

c)

Garbage value

Garbage value

d)

0

0

55.

What will be the array after executing this line ?

names[1] = "Sarah";

a)
b)
c)
56.

What is the correct way to initialize an array with 10 positions?

a)

int numbers = new int[10];

b)

int[] numbers = new int[];

c)

int[] numbers = new int[10];

d)

int[10] numbers = new int[10];

57.

In an array, the index of the first element is (a)  

58.

catch block is used to

a)

throw an exception

b)

create an exception

c)

handles an exception

d)

stops execution

59.

Abstract class can have

a)

Abstract methods

b)

Methods with code implementation

c)

Used to create objects

d)

Used to create subclasses

60.

What are the values of var1 and var2 when the code finishes executing?

a)

var1 = 1, var2 = 1

b)

var1 = 2 , var2 = 0

c)

var1 = 3, var2 = -1

d)

var1 = 0, var2 = 2

e)

The loop will cause a run-time error for division by zero

61.

Which are the types of operators seen? Select as many you think

a)

bitwise operator

b)

subtraction operator

c)

equality operator

d)

arithmetic operator

62.

select as many unary arithmetic operators as you see

a)

==

b)

--

c)

||

d)

!

63.

which description of these relational operators are incorrect?

a)

==(equal to)

b)

<(less than)

c)

>=(greater than)

d)

!=(less than equal to)

64.

which type of operator it is? i + =5

a)

addition assignment operator

b)

conditional operator

c)

arithmetic operator

d)

equality operator

65.

Which of the following can be operands of arithmetic operators?

a)

Numeric

b)

Boolean

c)

Both Numeric & Characters

d)

Characters

66.

Bytecode can be understood by the ________________________

a)

Any Machine

b)

Java Machine

c)

Virtual Machine

67.

Will this code compile?

a)

Yes

b)

No

68.

Will this code compile?

a)

Yes

b)

No

69.

Will this code compile without error?

a)

Yes

b)

No

70.

Will this code compile?

a)

Yes

b)

No

71.

What will happen when you run and compile the following code?

a)

1

b)

0

c)

compilation error

d)

runtime error

72.

What will happen when you run and compile the following code?

a)

Hello

b)

Compilation error

c)

Runtime error

d)

None of the above

73.

What will happen when you run and compile the following code?

a)

Hi

b)

Compilation error

c)

No output

d)

Runtime error

74.

Which class has defined the equals(object o) method?

a)

String

b)

Object

c)

Main

d)

System

75.

What will happen when you compile and run the following code?

a)

Int version

b)

Long version

c)

Compilation error

d)

Runtime error

76.

Which statement is true for the following code?

a)

The code will compile without changes.

b)

The code will compile if public tree{} {Plant{}:} is added to the tree class

c)

The code will compile if public tree{} {tree{}:} is added to the Plant class

d)

The code will compile if public plant{} {this {"fern"}:} is added to the Plant class

77.

what will be the result of the following code?

a)

Int long

b)

Short long

c)

Compilation fails

d)

An exception is thrown at the runtime

78.

Which three methods, inserted individual at line 14, will correctly complete class 2

a)

Int foo{}{/*more code here*/.}

b)

Void foo{}{/*more code here*/.}

c)

Public void foo{}{/*more code here*/.}

d)

Private void foo{}{/*more code here*/.}

e)

Protected void foo{}{/*more code here*/.}

79.

How do you insert COMMENTS in Java code?

a)

# This is a comment

b)

/* This is a comment

c)

// This is a comment

80.

How to declare a Static variable

a)

int a= 10;

b)

static a= 200;

c)

static int a= 100;

81.

How to declare a Static variable

a)

int a= 10;

b)

static a= 200;

c)

static int a= 100;

82.

Static variable is a Global variable

a)

True

b)

False

83.

NonStatic Variable is a Local Variable

a)

True

b)

False

84.

Where can we declare a Static Variable

a)

inside main function

b)

outside main function

85.

Where can we declare a nonStatic Variable

a)

inside main function

b)

outside main function

86.

Where can we declare Local Variable

a)

inside main function

b)

outside main function

87.

Can static and nonStatic variables declared as public

a)

Yes

b)

No

88.

is Local Variable and NonStatic variable are same

a)

True

b)

Local

89.

Can i have the same Global variable name for my Local Variable

a)

Yes

b)

No

90.

How to create an Object for my Class "Abc"

a)

Abc obj= new Abc;

b)

Abc = new Abc;

c)

Abc obj= new Abc();

91.

In Java , Data types are

a)

Primitive data type

b)

Non Primitive data type

c)

Both are correct

d)

Both are incorrect

92.

Java Access Modifiers are

a)

public,Private

b)

Protected

c)

Default

d)

All of these

93.

Math class is a part of Java.________ package

a)

io

b)

util

c)

lang

94.

All mathematical functions are included in a class called

a)

Math

b)

System

c)

Scanner

95.

This function returns the maximum of 2 numbers

a)

Math.min()

b)

Math.max()

c)

Math.minmax()

96.
_______ converts an assembly language program into machine language.
a)
Assembler
b)
Intrepreter
c)
Compiler
d)
All of the Above
97.

Which of the following are Java features?

a)

Object- oriented programming

b)

Class- based programming

c)

Bytecode is platform independent

d)

All of above

98.

Which laboratory was Java invented or developed in?

a)

Bell Laboratory

b)

Sun Microsystems

c)

Dennis Ritchie Office

d)

Johnson and Johnson

99.

Which of the below is valid way to instantiate an array in java?

a)

int myArray [] = {1, 3, 5};

b)

int [] myArray = {“1”, “2”, “3”};

c)

int myArray [] [] = {1,2,3,4};

d)

int [] myArray = (5, 4, 3);

100.

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.