Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Week 2

Total questions: 25

Worksheet time: 1hrs 5mins

Name
Class
Date
1.

Which of the following statements is/are true about the statement given below?

a)

String args[ ] is used to handle the command line arguments.

b)

static keyword allows calling the main method without using any object.

c)

The void keyword specifies that main does not return any value.

d)

The public keyword is an access modifier. It restricts the main method to be accessed from outside the program.

2.

Which of the following statements is/are true about data types in Java?

Statement 1: int and byte data types allows numbers/numeric values with fractions.

Statement 2: long and double data types does not allow numbers/numeric values with fractions. Statement 3: byte and short, data types does not allow numbers/numeric values with fractions.

a)

Statements 1, 2 and 3 are correct.

b)

Statement 1 and 2 are correct.

c)

Only statement 2 is correct.

d)

Only statement 3 is correct.

3.

Consider the variable declarations given below, and select the correct option.

int age=47;

int pincode=508206;

int days_of_a_week=7;

int hours_of_a_day=24;

a)

We can make variable age as final as it may be changed person to person.

b)

We cannot make variable days_of_a_week as final as its value must be constant.

c)

We can make variable hours_of_a_day as final as it is constant.

d)

We can not make variable pincode as final as it may be changed city to city.

4.

Consider the Java code given below and predict the output.

a)

99

b)

50

c)

101

d)

100

5.

Consider the Java code given below and predict the output.

a)

4

5

16

b)

3

4

12

c)

4

5

20

d)

4

4

16

6.

The _____________modifier indicates a constant.

a)

static

b)

public

c)

constant

d)

final

7.

Identify the correct piece of code and choose the correct option.

I. int a = (int)999.9;

II. byte b = (byte)500L;

III. long c = (byte)50;

IV. long d = 50;

a)

The above all statements are correct.

b)

IV

c)

I and II

d)

III

8.
a)

Runtime Error

b)

First Number: Null Second Number: Null

c)

Compilation Error

d)

First Number: 0 Second Number: 0

9.
a)

A-III, B-II, C-IV, D-I

b)

A-II, B-I, C-III, D-IV

c)

A-I, B-IV, C-II, D-III

d)

A-II, B-III, C-I, D-IV

10.

How is it possible to run the main method in Java without creating an object?

a)

The access modifier public helps the main() method to run independently without creating an object.

b)

The main() method is an exception. It is the only method that exist independently without the dynamic creation of an object.

c)

The modifier static helps the main() method to run independently without creating an object.

d)

Java is an object oriented programming language. Thus we need to create an object of the main class, and call our main() method to run. Hence the question is fallacious.

11.

Considering the following Java code, choose the correct statement from among the given options regarding this code.

a)

The code results in a compilation error as eid and ename instance variables should be initialized before using them.

b)

The code results in a compilation error as constructor is not defined.

c)

Program runs successfully, and the data members eid and ename contains random garbage value.

d)

Program runs successfully, and the data members eid and ename contains 0 and null respectively.

12.

Consider the statements given below and select the correct option.

Statement 1: Iterative statements allow your program to choose different paths of execution based upon the outcome of an expression or the state of a variable.

Statement 2:Selection/Conditional statements enable program execution to repeat one or more statements.

a)

Statement 1 correct and 2 incorrect.

b)

Statement 1 incorrect and 2 is correct.

c)

Statement 1 and 2 are correct.

d)

Statement 1 and 2 are incorrect.

13.

Consider the Java code given below and predict the output.

a)

Hello World! printed forever.

b)

Compilation fails due to error in line no 5.

c)

Nothing will be printed.

d)

1010

14.

Consider the java code given below and predict the output.

a)

00

11

22

33

b)

0

1

2

3

c)

Compilation fails.

d)

Generates no output.

15.

Which of the following loops will execute the body of loop even if the controlling state ment of the loop is false?

a)

for-each

b)

for

c)

do-while

d)

while

16.

Consider the java code given below and select the valid code snippet which calls the show().

a)

BoxEx box; box.show();

b)

BoxEx box=new BoxEx();

box.show();

c)

new BoxEx().show();

d)

BoxEx box; box=newBoxEx(); box.show();

17.

What will be the output/error?

a)

Compilation fails due to System.out.println(10+20+"IIT Madras");

b)

Compilation fails due to System.out.println("IIT Madras"+10+20);

c)

30IIT Madras

IIT Madras1020

d)

Exception at run time.

18.

Which of the following data type follows the object oriented paradigm in Java?

a)

int

b)

float

c)

String

d)

boolean

19.

Consider the Java code given below and predict the output.

a)

Hello World! printed 10 times.

b)

Hello World! printed 9 times.

c)

Compilation fails due to error in line no 6.

d)

Hello World! printed until stack over ow.

20.

Consider the Java code given below and predict the output.

a)

Compilation fails

b)

Generates no output

c)

Print numbers from 0 to 9 as output.

d)

0

21.

Consider the java code given below and predict the output.

a)

0

001

112

223

33

b)

0

1

2

3

c)

Generates no output.

d)

Compilation fails.

22.

Consider the Java code given below.

What will the output be if we provide Sri Lanka as the input for the program?

a)

Delhi is capital of India.

Colombo is capital of Sri Lanka.

Please enter valid country name:

b)

Colombo is capital of Sri Lanka

Please enter valid country name:

c)

Colombo is capital of India.

d)

Compilation fails.

23.

Consider the Java code given below.

a)

The code generates a compilation error.

b)

The code generates a run time error.

c)

Nothing will be printed.

d)

Hello World! would be printed forever.

24.

Consider the Java code given below.

a)

compilation failed.

b)

30

c)

20

d)

10

25.

Consider the Java code given below.

Choose the correct option regarding the given code.

a)

Generates output :

0

0

b)

Generates a compilation error

c)

Generates output : 0

d)

Generates no output but program compiles successfully.