wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Code A Thone Finals

Total questions: 45

Worksheet time: 41mins

Name
Class
Date
1.

Which operator cannot be used with if-else statement?

a)

<=

b)

||

c)

&&

d)

? :

2.

Predict the output of the following code snippet:

int a = 1;

int b = 2;

if (a == b)

System.out.println("Both values are equal");

else

System.out.println("Values are not equal");

4 lines
3.

Consider the following code snippet: if ( c > d) x = c; else x = d; Choose the correct option if the code mentioned above is rewritten using the ternary operator:

a)

x = (c > d) ? c : d;

b)

x = (c > d) ? d : c;

c)

x = (c > d) ? c : c;

d)

x = (c > d) ? d : d;

4.

Consider the following code snippet: int val = 2; switch (val) { case 1: System.out.println("Case 1"); break; case 2: System.out.println("Case 2"); break; default: System.out.println("No match found"); break; } Which of the following statements is correct?

a)

Any number of values

b)

2 values

c)

Only 1 value

d)

3 values

5.

Give the output of the Math.abs(x); when x = -9.99

a)

-9.99

b)

9.99

c)

0.99

d)

None

6.

Which of the following is false to find square of a number?

a)

Math.pow(a,2)

b)

a*a

c)

Math.sqrt(a,2)

d)

All of the above

7.

If a, b and c are the sides of a triangle then which of the following statement is true for: if(a!=b && a!=c && b!=c)?

a)

Equilateral triangle

b)

Scalene triangle

c)

Isosceles triangle

d)

All of the above

8.

To execute a loop 10 times, which of the following statement satisfies:

a)

for(i=6;i<=26;i=i+2)

b)

for(i=3;i<=30;i=i+3)

c)

for(i=0;i<10;i=i++)

d)

all of the above

9.

Give the output of the following snippet based on nested loops- int i,j; for (i=0; i<4; i++) { for (j=i; j>=0; j--) System.out.print(j); System.out.println();

4 lines
10.

Name the type of error- "Division by a variable that contains a value of zero"

a)

True

b)

False

11.

Which of these components are used in a Java program for compilation, debugging, and execution?

a)

JDK

b)

JVM

c)

JRE

d)

JIT

12.

The binary equivalent of hexadecimal digit E is

(a)  

13.

Predict the output of the following-

String str = "Computer Applications" + 1 + 0;

System.out.println("Understanding" + str);

4 lines
14.

Predict the output-

boolean p;

p = ("BLUEJ".length() > "bluej".length()) ? true: false;

4 lines
15.

Predict the output-

String str1 = "Information Technology";

String str2 = "information technology";

boolean p = str1.equalsIgnoreCase(str2);

System.out.println("The result is " + p);

4 lines
16.

What will be the value stored in the variable 'c' if the following statement is executed?

c = "COMPUTER".charAt("COMPUTER ".indexOf('P'))

(a)  

17.

What will be the output of the following program snippet?

s1 = "COMPUTER";

s2 = "computer";

System.out.println(s1.equals(s2));

4 lines
18.

What will be the output of the following program snippet?

str1 = "AMAN";

str2 = "AMIT";

System.out.println(str1.compareTo(str2));

4 lines
19.

Predict the output-

String str = "Information Technology";

int p;

p = str.indexOf('n');

System.out.println(p);

4 lines
20.

What was Java originally designed for?

a)

Interactive TV

b)

Internet

c)

Gaming

d)

Cars

21.

The

operator who also acts as a string concatenation _______

a)

a)

/

b)

b) *

c)

c)

+

d)

d) –

22.

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)

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

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

23.

Syntax

of the class variables________

a)

Class_name.class_variables

b)

public

static void main (String arg [])

c)

Class_name

object_name;

d)

Class

name_anyRef;

24.

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

25.

Which is

one of the symbol of array?

a)

{ }

b)

( )

c)

[ ]

d)

< >

26.

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

27.

JAVA

does not directly implement____________

a)

Multiple

inheritance

b)

Multilevel inheritance

c)

Hybrid inheritance

d)

Single inheritance

28.

The

interface item would inherit both the

constants-----------------------and---------------------

a)

Code, Variable

b)

Code, Name

c)

Code, Method

d)

Extends

29.

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

30.

How to

block the thread exceptions

a)

Sleep()

b)

Start()

c)

Stop()

d)

Run()

31.

When the

applet is terminated _________and________ methods are called sequence

a)

run()

and destroy()

b)

stop()

and destroy()

c)

run()

and stop()

d)

none

32.

what is

the purpose of for loops in applet?

a)

circles

b)

triangle

c)

rectangle

d)

square

33.

Which company owns Java?

a)

Oracle

b)

Microsoft

c)

Google

d)

Apple

e)

Intel

34.
Identify if the image is related to 'throws keyword + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
35.
Identify if the image is related to 'throws keyword + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
36.
Identify if the image is related to 'for-each loop + java'
a)
Related
b)
slightly related
c)
related but other topic
d)
not related
e)
i am not sure
37.
Which of these is a class which uses String as a key to store the value in object?
a)
Array
b)
ArrayList
c)
Dictionary
d)
Properties
38.

Consider the following operation performed on a stack of size 5.

Push(1);

Pop();

Push(2);

Push(3);

Pop();

Push(4);

Pop();

Pop();

Push(5);

After the completion of all operation, the number of elements present in stack are

a)

a)1

b)

b)2

c)

c)3

d)

d)4

39.

Two lists, A and B are implemented as singly linked link-lists. The address of the first and last node are stored in variables firstA and lastA for list A and firstB and lastB for list B. Given the address of a node is given in the

variable node, the element stored in the node can be accessed by the

statement node->data and the address to the next node can be accessed by node->next. Pankaj wants to append list B at end of list A. Which of the following

statements should he use?

a)

Op 1: lastB -> next = firstA

b)

Op 2: lastA = firstB

c)

Op 3: lastA->next = firstB

d)

Op 4: lastB = firstA

40.

What would be the answer to this expression tree?

a)

28

b)

27

c)

31

d)

29

41.

-Contains no duplicate elements.

-Can contain at most one Null value.

-Elements are not key-value pairs.

-Accessing an element can be almost as fast as performing a similar operation on an array.


Which of these classes provides the specified features?

a)

LinkedList

b)

TreeMap

c)

HashSet

d)

LinkedHashMap

e)

HashMap

42.

Nodes in a linked list contain two things

a)

Direction and a pointer

b)

Data and a pointer

c)

A Pointer and a reference

d)

A pointer and a node

43.

The situation when in a linked list Head==NULL

is

a)

Full

b)

Empty

c)

Half full

d)

saturated

44.

In the above image what will be printed when Head->next->data?

a)

83

b)

9

c)

27

d)

Error

45.

Complete the code in the red column

a)

string info; int link;

b)

int info; NodeType link;

c)

int info; string link;

d)

int info; NodeType * link;