wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Testtwentytwo

Total questions: 60

Worksheet time: 54mins

Name
Class
Date
1.

Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only. Given the representation, which of the following operation can be implemented in O(1) time?


a. Insertion at the front of the linked list

b.Insertion at the end of the linked list

c.Deletion of the front node of the linked list

d. Deletion of the last node of the linked list

a)

a and c

b)

a and b

c)

b and d

d)

d and a

2.

Consider an array consisting of –ve and +ve numbers. What would be the worst case time complexity of an algorithm to segregate the numbers having same sign altogether i.e all +ve on one side and then all -ve on the other?

a)

O(N)

b)

O(N Log N)

c)

O(N * N)

d)

O(N Log Log N)

3.

Is the below code written correctly?

a)

Yes. You can use non-static method of outer class inside a static nested class directly.

b)

No. You can’t use non-static method of outer class inside a static nested class directly.

4.

Does below program print “SUCCESS” on the console when you run it?

a)

YES

b)

NO

5.
a)

ERROR

b)

3131

c)

3132

d)

3133

6.
String word = "A few good men";
What is word.charAt(7) ?
a)
o
b)
g
c)
7
d)
good men
7.
String word = "A few good men";
What is word.indexOf(“bad”)?
a)
0
b)
-1
c)
3
8.

Given the following code segment, what is the value of sum after this code executes?

a)

4

b)

8

c)

9

d)

12

e)

10

9.

a)

0

b)

1

c)

3

d)

-4

10.

A CONTINUE statement inside a Loop like WHILE, FOR, DO-WHILE and Enhanced-FOR causes the program execution ___ the loop.

a)

A) Skip

b)

Skip present iteration and continue with next iteration of the loop

c)

Exit

d)

None

11.

What is the purpose of 'throw' keyword

a)

To Raise an exception explicityly

b)

To Raise an exception implicityly

c)

To create user defined exceptions

d)

To create custom exceptions

12.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

13.

Choose the CORRECT exception


String department="JTMK";

Integer no=Integer.parseInt(department);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

14.

class Main {

public static void main(String args[]) {

try {

throw 10;

}

catch(int e) {

System.out.println("Got the Exception " + e);

}

}

}

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

none

15.

Which of the following describes the correct sequence of the steps involved in making a connection with a database.

1. Loading the driver

2. Process the results.

3. Making the connection with the database.

4. Executing the SQL statements.

a)

1 ,3,4,2

b)

1,2,3,4

c)

1,4,3,2

d)

1,2,4,3

16.

How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?

a)

UPDATE Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’

b)

MODIFY Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’

c)

MODIFY Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’

d)

UPDATE Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’

17.

Identify the last node in the post-order traversal of this binary tree.

a)

8

b)

1

c)

9

d)

5

18.

At the end of this fragment of code what is r1.count value?

a)

10

b)

-5

c)

6

d)

7

e)

8

19.

predict output

a)

10

b)

5

c)

error

20.

Output of following Java Program?

a)

Derived::show() called

b)

Base::show() called

c)

Run time Error

d)

Compilation Error

21.

Which of the following class doesn’t implement the Set interface?

a)

HashSet

b)

LinkedHashSet

c)

TreeSet

d)

None of the above

22.

It keeps the data and the code safe from external interference.

a)

Polymorphism

b)

ArrayList

c)

Autoboxing

d)

Encapsulation

23.

What is the output of this program?

a)

1 2

b)

2 1

c)

Runtime Error

d)

Compilation Error

24.

What is the output of this program?

a)

0

b)

1

c)

2

d)

Compilation Error

25.

Which of the following is/are true about constructors in Java?

a)

1

b)

1,2

c)

1, 2, 4

d)

1,2,3 & 4

26.

int x = "Mary".compareTo("Molly");

if (x>=0) System.out.print("Yes");

else System.out.print("No");


What is the output?

a)

Yes

b)

No

c)

There is no output.

d)

This code will not compile.

27.
Which of the following is used to call stored procedure?
a)
Statement
b)
PreparedStatement
c)
CallableStatment
d)
CalledStatement
28.
What is used to execute parameterized query?
a)
Statement interface
b)
PreparedStatement interface
c)
ResultSet interface
d)
None
29.

The interface ResultSet has a method, getMetaData(), that returns a/an

a)

Tuple

b)

Value

c)

Object

d)

Result

30.

Which of this statement is incorrect?

a)

All object of a class are allotted memory for the all the variables defined in the class

b)

If a function is defined public it can be accessed by object of other class by inheritation

c)

main() method must be made public

d)

All object of a class are allotted memory for the methods defined in the class

31.

What is the stored in the object obj in following lines of Java code?


box obj;

a)

Memory address of allocated memory of object

b)

NULL

c)

Any arbitrary pointer

d)

Garbage

32.

What is the output

a)

4.1

b)

8.1

c)

4

d)

Compiler error

33.

What is the output

a)

Tyer car brake horn

b)

car

brake

horn

c)

horn brake car Tyer

d)

horn

brake

car

34.

What will be the output of the program?

try

{

int x = 0;

int y = 5 / x;

}

catch (Exception e)

{

System.out.println("Exception");

}

catch (ArithmeticException ae)

{

System.out.println(" Arithmetic Exception");

}

System.out.println("finished");

a)

finished

b)

runtime error.

c)

Compilation fails

d)

Exception.

35.

output of the program

a)

inside static block

a = 4

inside constructor

a = 11

b)

Compiler Error

c)

Run Time Error

d)

inside static block

a = 4

inside constructor

a = 5

e)

inside static block

a = 10

inside constructor

a = 11

36.

Predict the output:

a)

20

b)

10

c)

Error in Object creation

d)

None of the above

37.

What will be the output of the following Java program?

a)

0 1 2

b)

0 2 4

c)

0 0 4

d)

0 1 4

38.

What is the output of this program?

a)

a=10

b)

a=20

c)

Compilation Error

d)

No Error, but no output

39.

If two classes combine some private data members and provides public member functions to access and manipulate those data members. Where is abstraction used?

a)

Using private access specifier for data members

b)

Using class concept with both data members and member functions

c)

Using public member functions to access and manipulate the data members

d)

Data is not sufficient to decide what is being used

40.

What is instance variable?

a)

Instance variables are static variables within a class but outside any method

b)

Instance variables are variables defined inside methods, constructors or blocks

c)

Instance variables are variables within a class but outside any method

d)

None of the mentioned

41.

Where an object of a class get stored?

a)

Heap

b)

Stack

c)

Disk

d)

File

42.

Static method

a)

A method that can is fixed to a class and can't be used elsewhere

b)

A method that can be used only when creating an instance of the class

c)

A method that can be used without creating an instance of the class

d)

A method that doesn't move

43.

Which of these class contains the methods print() & println()?

a)

System

b)

System.out

c)

BUfferedOutputStream

d)

PrintStream

44.

Which exception is thrown by read() method?

a)

IOException

b)

InterruptedException

c)

SystemException

d)

SystemInputException

45.

What is the time complexity of the code

a)

O(N)

b)

O(N*log(N))

c)

O(N * Sqrt(N))

d)

O(N*N)

46.

What does it mean when we say that an algorithm X is asymptotically more efficient than Y? 

a)

X will always be a better choice for small inputs

b)

X will always be a better choice for large inputs

c)

Y will always be a better choice for small inputs

d)

X will always be a better choice for all inputs

47.

What is output by the code?

a)

[ ]

b)

[1]

c)

[1, aplus]

d)

[aplus]

48.

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

a)

java.util.HashSet

b)

java.util.LinkedHashSet

c)

java.util.List

d)

java.util.ArrayList

49.

The default capacity of a Vector is:

a)

10

b)

12

c)

8

d)

0

50.

Find the output

public class TreeMapTest {

public static void main(String args[]) {

Map<Integer, String> m = new TreeMap<Integer, String>();

m.put(11, "audi");

m.put(null, null);

m.put(11, "bmw");

m.put(null, "ferrari");

System.out.println(m.size());

System.out.println(m);

}

a)

Nullpointer exception

b)

compiler error

c)

2

d)

Null value

51.

Which of the following is a correct difference between ArrayList and LinkedList?

a)

ArrayList uses a doubly linked list whereas the LinkedList uses dynamic array.

b)

ArrayList uses a dynamic array whereas the LinkedList uses doubly linked list.

c)

ArrayList uses a single linked list whereas the LinkedList uses dynamic array.

d)

None

52.
We are use Scanner Library in java for...
a)
Give permissions to the user
b)
Correcting software errors
c)
Allows user to read data
d)
Allows the user to enter data
53.
When we want to print in Java, we use the code ......
a)
system.out.print();
b)
System.out.println();
c)
System.Out.Printf();
d)
System.out.show();
54.

What's the value of below?


int i=5;

System.out.println(i++);

System.out.println(i);

System.out.println(++i);

a)

5

6

7

b)

6

6

7

c)

6

7

8

d)

5

5

6

55.

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

56.

Find the output of the following snippet.


class Numbers

{

public static void main(String args[])

{

int a=20, b=10;

if((a<b)&&(b++ <25))

{

System.out.println("this is any language logic");

}

System.out.println(b);

}

}

a)

10

b)

12

c)

11

d)

Compilation Error

57.

Please write correct output in following space-

a)

10

b)

20

c)

No Output

d)

Error

58.

which one of the following is a legal decelration of a two- dimensional array of integers

a)

int[] a[] = new int[5][];

b)

int[5][5] a = new int[][];

c)

int a = new int[5,5];

d)

int[][] a = new int[][5];

59.

Which of these is method of ObjectOutputStream class used to write the object to output stream as required?

a)

Write()

b)

write()

c)

StreamWrite()

d)

writeObject()

60.

Predict the output of the following program.


class A{

int a=40;

public static void main(String args[]){

System.out.println(a);

}

}

a)

Compilation Error

b)

40

c)

0

d)

None of the above