wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java

Total questions: 61

Worksheet time: 31mins

Name
Class
Date
1.

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.

2.

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)

3.

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

a)

Line 2

b)

Line 8

c)

Line 13

d)

Line 10

4.

The different 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.

5.

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;

6.

Is String a primitive data type?

a)

Yes

b)

No

c)

Both

7.

Which method to use to find length of a string?

a)

length()

b)

size()

c)

long()

d)

count()

8.

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

9.

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

10.

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"

11.

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

12.
Inheritance is used when the relationship between two classes is a(n) _______ relationship.
a)
"HAS-A"
b)
"PART-OF-A"
c)
"IS-A"
d)
inverse
13.
If more than one class implements an interface, its methods are ____.
a)
aggregated
b)
public
c)
dependent
d)
polymorphic
14.

The following Syntax is used for?


class Subclass-name extends Superclass-name

{

//methods and fields

}

a)

Polymorphism

b)

Encapsulation

c)

Inheritance

d)

None of the above

15.

A class that is inherited is called a ______ .

a)

superclass

b)

Subclass

c)

subsetclass

d)

Relativeclass

16.

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

17.

try block may or may not contains catch blocks

a)

True

b)

False

18.

How to create our own exception

a)

using 'throw' keyword

b)

using 'throws' keyword

c)

using 'finally' keyword

d)

using 'throwable' keyword

19.

Choose the CORRECT exception


String department="JTMK";

Integer no=Integer.parseInt(department);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

20.

Choose an exception if attempt to divide number by zero


int number = 89 / 0;

System.out.println("The answer is " + number);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundException

21.

Default value of a java thread is

a)

0

b)

1

c)

5

d)

10

22.

If a priority of a java thread is 3 then the default priority of its child thread will be

a)

0

b)

1

c)

5

d)

3

23.

Daemon thread runs in

a)

BackGround

b)

Foreground

c)

Both

d)

none

24.

Which method is used to wait for child threads to finish in Java?

a)

Wait ()

b)

Sleep ()

c)

Join ()

d)

isAlive()

25.

The life cycle of a thread in java is controlled by

a)

JRE

b)

JDK

c)

JVM

d)

None

26.

Which method is used to get current running thread object?

a)

runningThread()

b)

currentThread()

c)

runnableThread()

d)

None

27.

Thread priority in Java is?

a)

Integer

b)

Float

c)

Double

d)

Long

28.

Object may be communicate --------------

a)

Through object

b)

Through class

c)

Through methods

d)

Through

data

29.

Consider

the following Java program :

public class Compute {

public static void main (string args [ ])

{

int result, x ;

x = 1 ;

result = 0;

while (x < = 10) {

if (x%2 == 0) result + = x ;

+ + x ;

}

System.out.println(result) ;

}

}

Which of the following will be the output of the above program?

a)

55

b)

30

c)

25

d)

35

30.

Which of

the following variable declaration would NOT compile in a java program?

a)

int

var;

b)

int VAR;

c)

int var1;

d)

int

1_var;.

31.

Which

one is java token?

a)

Identifiers

b)

Operators

c)

Literals

d)

all the

above

32.

What

will be printed as the output of the following program?

public class testincr

{

public static void main(String args[])

{

int i = 0;

i = i++ + i;

System.out.println(“I = ” +i);

}

}

a)

I=0

b)

I=1

c)

I=2

d)

Error

33.

The

operator who also acts as a string concatenation _______

a)

a)

/

b)

b) *

c)

c)

+

d)

d) –

34.

What is the type and value of the following expression? (Notice the integer

division)

-4 + 1/2 + 2*-3 + 5.0

a)

int -5

b)

double

-4.5

c)

int

-4

d)

double

-5.0

35.

Use the

following declaration and initialization to evaluate the Java

expressions

int a = 2, b = 3, c = 4, d = 5;

float k = 4.3f;

System.out.println (c=c++);

a)

2

b)

4

c)

5

d)

8

36.

Predict

the output of following Java Programs.

// filename Main.java

class Test {

protected int x, y;

}

class Main {

public static void main(String

args[]) {

Test t = new Test();

System.out.println(t.x +

" " + t.y);

}

}

a)

1,1

b)

1,2

c)

0,0

d)

Error

37.

What is

casting a value?

a)

expression

b)

ratio

c)

operator

d)

all of the above

38.

Consider the following Java program :

class IfStatement{

public static void main(String args[])

{

int a=2, b=3;

if (a==3)

if (b==3)

System.out.println(“===============”);

else

System.out.println(“#################”);

System.out.println(“&&&&&&&&&&&”);

}

}

Which of the following will the output be?

a)

===============

b)

#################

&&&&&&&&&

c)

&&&&&&&&&&&

d)

===============

#################

39.

The

general form of constructing an array is _______

a)

Datatype

arr-name [];

b)

Datatype

[]arr-name;

c)

arr-name=

new datatype[noOfElements];

d)

arr-name.length

40.

Which is

one of the symbol of array?

a)

{ }

b)

( )

c)

[ ]

d)

< >

41.

Consider

the following class definition:

public class MyClass

{

private int value;

public void setValue(int i){ / code / }

// Other methods…

}

The method setValue assigns the value of i to the instance field value.

What could you write for the implementation of setValue?

a)

value = i;

b)

this.value = i;

c)

value == i;

d)

Both

(A) and (B) and above

42.

What is

a keyword used in extending interfaces?

a)

Extern

b)

Extend

c)

Extnd

d)

extends

43.

Predict

the output of following Java programs.

package main;

class Base {

public void Print() {

System.out.println("Base"); }

}

class Derived extends Base {

public void Print() {

System.out.println("Derived");

} }

class Main{

public static void DoPrint( Base

o ) {

o.Print();

}

public static void main(String[]

args)

{ Base x = new Base();

Base y = new Derived();

Derived z = new Derived();

DoPrint(x);

DoPrint(y);

DoPrint(z);

} }

a)

Base,

Derived, Derived

b)

Derived,

Derived ,Derived

c)

Derived,

Derived, Base

d)

None

44.

Expand

API

a)

Application

programming interface

b)

Advanced programming interface

c)

Architecture programming interface

d)

Artificial programming interface

45.

Multithreading

concept can be divided into _________

a)

Class

b)

Processes

c)

Method

d)

Object

46.

Applet

program are used to the ----------------

a)

Internet computing

b)

Cloud Computing

c)

Grid Computing

d)

Green Computing

47.

The

Graphics object g is an argument of -------------------------

a)

Print()

b)

Applet()

c)

Graphics()

d)

paint()

48.

which is

one of the initialization state?

a)

int()

b)

init()

c)

initial()

d)

inti()

49.

what is

the executable applet?

a)

.class

b)

.object

c)

.method

d)

.function

50.

which is

used for graphics object?

a)

<g>

b)

(g)

c)

g.

d)

,g

51.

The keyword "method" is another name for

a)

an object

b)

a class

c)

a function

d)

a variable

52.

Which of the following is incorrect?

a)

int count = 50.0;

b)

int salary = 50_000;

c)

int salary = 50_00;

d)

all of these are incorrect

53.

The numeric type int uses how many bits?

a)

16

b)

32

c)

48

d)

64

54.

What would the new value of A be?

A=1;

a++;

a)

1

b)

2

c)

3

d)

4

55.

What does the following code output?

int x = 1;

System.out.println(x++);

a)

1

b)

2

c)

compilation error

d)

runtime error

56.
Which one of the following is NOT a logical operator?
a)
||
b)
&&
c)
$$
d)
!
57.

If a=2, b=5, c=3

Find result for : 8 * (a + b + c) – a % c

a)

80

b)

81

c)

77

d)

78

58.

int a = 2, b = 2, c = 0;

double d = 30.1;


Find answer for = (a > b) &&(( c <d) || (c!=a))

a)

35.9

b)

80

c)

true

d)

false

59.

int a = 2, b = 2, c = 0;

double d = 30.1;


Find answer for = (a > b) &&(( c <d) || (c!=a))

a)

35.9

b)

80

c)

true

d)

false

60.

When was Java released?

a)

1975

b)

1994

c)

1995

d)

1996

e)

1997

61.

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

a)

Line 2

b)

Line 8

c)

Line 13

d)

Line 10