WorksheetsTesttwentytwo
Total questions: 60
Worksheet time: 54mins
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 and c
a and b
b and d
d and a
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?
O(N)
O(N Log N)
O(N * N)
O(N Log Log N)
Is the below code written correctly?
Yes. You can use non-static method of outer class inside a static nested class directly.
No. You can’t use non-static method of outer class inside a static nested class directly.
Does below program print “SUCCESS” on the console when you run it?
YES
NO
ERROR
3131
3132
3133
What is word.charAt(7) ?
What is word.indexOf(“bad”)?
Given the following code segment, what is the value of sum after this code executes?
4
8
9
12
10
0
1
3
-4
A CONTINUE statement inside a Loop like WHILE, FOR, DO-WHILE and Enhanced-FOR causes the program execution ___ the loop.
A) Skip
Skip present iteration and continue with next iteration of the loop
Exit
None
What is the purpose of 'throw' keyword
To Raise an exception explicityly
To Raise an exception implicityly
To create user defined exceptions
To create custom exceptions
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Choose the CORRECT exception
String department="JTMK";
Integer no=Integer.parseInt(department);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundsException
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
Got the Exception 10
Got the Exception 0
Compiler Error
none
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.
1 ,3,4,2
1,2,3,4
1,4,3,2
1,2,4,3
How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?
UPDATE Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
MODIFY Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
MODIFY Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
UPDATE Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
Identify the last node in the post-order traversal of this binary tree.
8
1
9
5
At the end of this fragment of code what is r1.count value?
10
-5
6
7
8
predict output
10
5
error
Output of following Java Program?
Derived::show() called
Base::show() called
Run time Error
Compilation Error
Which of the following class doesn’t implement the Set interface?
HashSet
LinkedHashSet
TreeSet
None of the above
It keeps the data and the code safe from external interference.
Polymorphism
ArrayList
Autoboxing
Encapsulation
What is the output of this program?
1 2
2 1
Runtime Error
Compilation Error
What is the output of this program?
0
1
2
Compilation Error
Which of the following is/are true about constructors in Java?
1
1,2
1, 2, 4
1,2,3 & 4
int x = "Mary".compareTo("Molly");
if (x>=0) System.out.print("Yes");
else System.out.print("No");
What is the output?
Yes
No
There is no output.
This code will not compile.
The interface ResultSet has a method, getMetaData(), that returns a/an
Tuple
Value
Object
Result
Which of this statement is incorrect?
All object of a class are allotted memory for the all the variables defined in the class
If a function is defined public it can be accessed by object of other class by inheritation
main() method must be made public
All object of a class are allotted memory for the methods defined in the class
What is the stored in the object obj in following lines of Java code?
box obj;
Memory address of allocated memory of object
NULL
Any arbitrary pointer
Garbage
What is the output
4.1
8.1
4
Compiler error
What is the output
Tyer car brake horn
car
brake
horn
horn brake car Tyer
horn
brake
car
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");
finished
runtime error.
Compilation fails
Exception.
output of the program
inside static block
a = 4
inside constructor
a = 11
Compiler Error
Run Time Error
inside static block
a = 4
inside constructor
a = 5
inside static block
a = 10
inside constructor
a = 11
Predict the output:
20
10
Error in Object creation
None of the above
What will be the output of the following Java program?
0 1 2
0 2 4
0 0 4
0 1 4
What is the output of this program?
a=10
a=20
Compilation Error
No Error, but no output
If two classes combine some private data members and provides public member functions to access and manipulate those data members. Where is abstraction used?
Using private access specifier for data members
Using class concept with both data members and member functions
Using public member functions to access and manipulate the data members
Data is not sufficient to decide what is being used
What is instance variable?
Instance variables are static variables within a class but outside any method
Instance variables are variables defined inside methods, constructors or blocks
Instance variables are variables within a class but outside any method
None of the mentioned
Where an object of a class get stored?
Heap
Stack
Disk
File
Static method
A method that can is fixed to a class and can't be used elsewhere
A method that can be used only when creating an instance of the class
A method that can be used without creating an instance of the class
A method that doesn't move
Which of these class contains the methods print() & println()?
System
System.out
BUfferedOutputStream
PrintStream
Which exception is thrown by read() method?
IOException
InterruptedException
SystemException
SystemInputException
What is the time complexity of the code
O(N)
O(N*log(N))
O(N * Sqrt(N))
O(N*N)
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
X will always be a better choice for small inputs
X will always be a better choice for large inputs
Y will always be a better choice for small inputs
X will always be a better choice for all inputs
What is output by the code?
[ ]
[1]
[1, aplus]
[aplus]
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
The default capacity of a Vector is:
10
12
8
0
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);
}
Nullpointer exception
compiler error
2
Null value
Which of the following is a correct difference between ArrayList and LinkedList?
ArrayList uses a doubly linked list whereas the LinkedList uses dynamic array.
ArrayList uses a dynamic array whereas the LinkedList uses doubly linked list.
ArrayList uses a single linked list whereas the LinkedList uses dynamic array.
None
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
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 = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
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);
}
}
10
12
11
Compilation Error
Please write correct output in following space-
10
20
No Output
Error
which one of the following is a legal decelration of a two- dimensional array of integers
int[] a[] = new int[5][];
int[5][5] a = new int[][];
int a = new int[5,5];
int[][] a = new int[][5];
Which of these is method of ObjectOutputStream class used to write the object to output stream as required?
Write()
write()
StreamWrite()
writeObject()
Predict the output of the following program.
class A{
int a=40;
public static void main(String args[]){
System.out.println(a);
}
}
Compilation Error
40
0
None of the above
