Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Programming

Total questions: 20

Worksheet time: 12mins

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