Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz

Total questions: 28

Worksheet time: 16mins

Name
Class
Date
1.

1. Which of this method is given parameter via command line arguments?

a)

a) main()

b)

b) recursive() method

c)

c) Any method

d)

d) System defined methods

2.

What are the Type Conversions available in Java language?

a)

A) Narrowing Type Conversion

b)

B) Widening Type Conversion

c)

A and B

d)

D) None of the above

3.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

4.

Which type of loop is best known for its boolean condition that controls entry to the loop?

a)

A. do-while loop

b)

B. for (traditional)

c)

C. for-each

d)

D. while

5.

What will be the Output of the below code:

public class Demo{

public static void main(String[] arr){

}

public static void main(String arr){

}

}

a)

a) Nothing

b)

b) Error

c)

C) Finite

d)

d) Hii

6.

char is 2 byte in storage?

a)

True

b)

False

7.

Name the data type: '3'

a)

int

b)

char

c)

String

d)

None of the above

8.

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

a)

boolean

b)

String

c)

double

d)

int

9.
What data type would be best used to record an email address?
a)
String
b)
Integer
c)
Real
d)
Character
10.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

11.

What is the output of the following code snippet?

int i = 0; for(i = 0 ; i < 5; i++)

{ }

System.out.println(i);

a)

A. 5

b)

B. 0

c)

C. 4

d)

D. Compilation Error

12.

Function of the Scanner class to accept a float literal from the user is

a)

nextInt( )

b)

hasNext( )

c)

next( )

d)

nextFloat( )

13.

Predict the value of k,

int k =10;

k=k+k++;

a)

11

b)

20

c)

21

d)

22

14.
Which of these is not a Thread state?
a)
New
b)
Runnable
c)
sleep
d)
terminated
15.

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

a)

try

b)

catch

c)

finally

d)

throw

16.

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

17.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

18.

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

19.

class exception_handling

{ public static void main(String args[])

{ try

{ int a, b;

b = 0;

a = 5 / b;

System.out.print("A");

} catch(ArithmeticException e)

{ System.out.print("B");

}

finally

{ System.out.print("C");

}

}

}

a)

A

b)

B

c)

AC

d)

BC

20.

Find the output for the following.

public class IncDec

{

public static void main(String s[])

{

int a = 1;

int b = 2;

int c;

int d;


c = ++b;

d = a++;


c++;


System.out.println("a = " + a);

System.out.print("b = " + b);

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

System.out.print("d = " + d);

}

}

a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2

21.

Q 1. Consider the following Java methods.

int func2(int w) { return w * 3; } int func1 (int a, int b) { int n = a + b; return 2 + func2(n); } int start() { int z = 4; return func1(z, 1) - 3; }

a)

14

b)

0

22.

Consider the following Java methods.

int f(int x) { return x*2 - 1; } int h() { int a = 3; int b = f(a) + f(4); return b; }

a)

12

b)

15

23.

Consider the following method g.

int g (int a) { if (a < 9) { return 9; } if (a < 7) { return 7; } if (a < 4) { return 4; } return 0; }

a)

12

b)

36

24.

Consider the following method k.

int k (int a, int b) { if (a < b) { if (b > 4) { return 0 ; } else { return 1; } } else { if (a > 4) { return 2; } else { return 3; } } }

For which of the values a and b would 2 be the return value?

a)

a=12, b= 12

b)

a=6, b=6

c)

a=0, b= 0

25.

Consider the following method play, and assume appropriate import statements are there for classes used in this function.

public void play () { Frog fred = new Frog(); Cat jiang = new Cat(); fred.hop(4); jiang.jump(5, fred); String greet = That is all"; fred.say(greet, 3); }

a)
  • Only say

b)
  • hop and say

c)
  • Only jump

  • hop,

d)
  • jump and say

  • Only hop

26.
Enrolment Number
4 lines
27.
Name of Student
4 lines
28.
Class with Branch
4 lines