Sie sind auf Seite 1von 13

SLOT 2

1. What will be the output of this program?

public class RTExcept


{
public static void throwit ()
{
System.out.print("throwit ");
Throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}
A. hello throwit caught
B. Compailation error
C. hello throwit RuntimeException caught after
D. hello throwit caught finally after
2. What will be the output of the following Java program?
class newthread extends Thread
{
Thread t;
String name;
newthread(String threadname)
{
name = threadname;
t = new Thread(this,name);
t.start();
}
public void run()
{
}

}
class multithreaded_programing
{
public static void main(String args[])
{
newthread obj1 = new newthread("one");
newthread obj2 = new newthread("two");
try
{
obj1.t.wait();
System.out.print(obj1.t.isAlive());
}
catch(Exception e)
{
System.out.print("Main thread interrupted");
}
}
}
A. True B. false C. Main thread interrupted D. NONE
3. What will be the output of the following Java program?

class newthread extends Thread


{
Thread t;
String name;
newthread(String threadname)
{
name = threadname;
t = new Thread(this,name);
t.start();
}
public void run()
{
}

}
class multithreaded_programing
{
public static void main(String args[])
{
newthread obj1 = new newthread("one");
newthread obj2 = new newthread("two");
try
{
System.out.print(obj1.t.equals(obj2.t));
}
catch(Exception e)
{
System.out.print("Main thread interrupted");
}
}
}

A. True B. false C. Main thread interrupted D. NONE


4. What will be the output of the following Java program?

class newthread extends Thread


{
Thread t;
newthread()
{
t1 = new Thread(this,"Thread_1");
t2 = new Thread(this,"Thread_2");
t1.start();
t2.start();
}
public void run()
{
t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}

A. True B. false C. Main thread interrupted D. NONE

5. What will be the output of the following Java program?

import java.io.*;
class filesinputoutput
{
public static void main(String args[])
{
InputStream obj = new FileInputStream("inputoutput.java");
System.out.print(obj.available());
}
}

A. true B. false C. prints number of bytes in file


D prints number of characters in the file
6. What will be the output of the following Java program?

import java.io.*;
public class filesinputoutput
{
public static void main(String[] args)
{
String obj = "abc";
byte b[] = obj.getBytes();
ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
for (int i = 0; i < 2; ++ i)
{
int c;
while((c = obj1.read()) != -1)
{
if(i == 0)
{
System.out.print(Character.toUpperCase((char)c));
obj2.write(1);
}
}
System.out.print(obj2);
}
}
}
A. AaBaCa B. ABCaaa C. AaaBaaCaa D. AaBaaCaaa
7. What will be the output of the following Java program?
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
public void push(E obj)
{
stk.push(obj);
}
public E pop()
{
E obj = stk.pop();
return obj;
}
}
class Output
{
public static void main(String args[])
{
genericstack <Integer> gs = new genericstack<Integer>();
gs.push(36);
System.out.println(gs.pop());
}
}A. Runtime Error B. Compilation Error
8. What will be the output of the following Java code?

import java.util.*;
class properties
{
public static void main(String args[])
{
Properties obj = new Properties();
obj.put("AB", new Integer(3));
obj.put("BC", new Integer(2));
obj.put("CD", new Integer(8));
System.out.print(obj.keySet());
}
}

A. {3, 2, 8} B. [3, 2, 8] C. [AB, BC, CD] D. {AB, BC, CD}

9. What will be the output of the following Java code?

class newthread implements Runnable


{
Thread t;
newthread()
{
t1 = new Thread(this,"Thread_1");
t2 = new Thread(this,"Thread_2");
t1.start();
t2.start();
}
public void run()
{
t2.setPriority(Thread.MAX_PRIORITY);
System.out.print(t1.equals(t2));
}
}
class multithreaded_programing
{
public static void main(String args[])
{
new newthread();
}
}
A. false B.truetrue C.falsefalse D.true
10. What will be the output of the following Java code?
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
public void push(E obj)
{
stk.push(obj);
}
public E pop()
{
E obj = stk.pop();
return obj;
}
}
class Output
{
public static void main(String args[])
{
genericstack <String> gs = new genericstack<String>();
gs.push("Hello");
System.out.println(gs.pop());
}
}

A. H B. Hello C. Runtime Error D. Compilation Error


11. What will be the result of attempting to compile the following program?
public class MyClass {
long var;
public void MyClass(long param) { var = param; } //(1)
public static void main(String[] args) {
MyClass a,b;
a = new MyClass(); //(2)
b = new MyClass(5); //(3)
}
}
A. A compilation ERROR will occur at (1), since constructors cannot specify a return value
B. A compilation error will occur at (2), since the class does not have a default constructor
C. A compilation error will occur at (3), since the class does not have a constructor which
takes one argument of type int.
D. The program will compile correctly
12. What will be the output of the following Java code snippet?

enum Enums
{
A, B, C;

private Enums()
{
System.out.println(10);
}
}

public class MainClass


{
public static void main(String[] args)
{
Enum en = Enums.B;
}
}
A. 10 B. Compilation Error C. 10 D. Runtime Exception
10 10
10
13. Which of the following line of code is suitable to start a thread ?

class X implements Runnable


{
public static void main(String args[])
{
/* Missing code? */
}
public void run() {}
}
A. Thread t = new Thread(X); B. Thread t = new Thread(X); t.start();
C. X run = new X(); Thread t = new Thread(run); t.start();
D. Thread t = new Thread(); x.run();
14. What will be the output of the program?
package foo;
import java.util.Vector; /* Line 2 */
private class MyVector extends Vector
{
int i = 1; /* Line 5 */
public MyVector()
{
i = 2;
}
}
public class MyNewVector extends MyVector
{
public MyNewVector ()
{
i = 4; /* Line 15 */
}
public static void main (String args [])
{
MyVector v = new MyNewVector(); /* Line 19 */
}
}
A. Compilation will succeed. B. Compilation will fail at line 3.
C. Compilation will fail at line 5. D. Compilation will fail at line 15
15. What will be the output of the program?
TreeSet map = new TreeSet();
map.add("one");
map.add("two");
map.add("three");
map.add("four");
map.add("one");
Iterator it = map.iterator();
while (it.hasNext() )
{
System.out.print( it.next() + " " );
}
A. one two three four B. four three two one
C. four one three two D. one two three four one

16. Select how you would start the program to cause it to print: Arg is 2

public class Myfile


{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
A. java Myfile 222 B. java Myfile 1 2 2 3 4
C. java Myfile 1 3 2 2 C. java Myfile 0 1 2 3
17. What will be the output of the program?
public class BoolTest
{
public static void main(String [] args)
{
int result = 0;

Boolean b1 = new Boolean("TRUE");


Boolean b2 = new Boolean("true");
Boolean b3 = new Boolean("tRuE");
Boolean b4 = new Boolean("false");

if (b1 == b2) /* Line 10 */


result = 1;
if (b1.equals(b2) ) /* Line 12 */
result = result + 10;
if (b2 == b4) /* Line 14 */
result = result + 100;
if (b2.equals(b4) ) /* Line 16 */
result = result + 1000;
if (b2.equals(b3) ) /* Line 18 */
result = result + 10000;

System.out.println("result = " + result);


}
}
A. 0 B. 1 C. 10 D. 10010
18. What will be the output of the program?
public class Example
{
public static void main(String [] args)
{
double values[] = {-2.3, -1.0, 0.25, 4};
int cnt = 0;
for (int x=0; x < values.length; x++)
{
if (Math.round(values[x] + .5) == Math.ceil(values[x]))
{
++cnt;
}
}
System.out.println("same results " + cnt + " time(s)");
}
}
A. same results 0 time(s) B. same results 2 time(s)
C. same results 4 time(s) D. Compilation fails.
19. which line is an example of an inappropriate use of assertions?
public class Test2
{
public static int x;
public static int foo(int y)
{
return y * 2;
}
public static void main(String [] args)
{
int z = 5;
assert z > 0; /* Line 11 */
assert z > 2: foo(z); /* Line 12 */
if ( z < 7 )
assert z > 4; /* Line 14 */

switch (z)
{
case 4: System.out.println("4 ");
case 5: System.out.println("5 ");
default: assert z < 10;
}

if ( z < 10 )
assert z > 4: z++; /* Line 22 */
System.out.println(z);
}
}
A. Line 11 B. Line 12 C. Line 14 D. Line 22
20. Find the Missing statement in the bellow code
Public class foo
{
Public static void main(String[] args)throw Exception
{
Java.io.PrintWriter out = new java.io.PrintWriter();
New java.io.Output.StreamWriter(System.out,true);
Out.println(“Hello”);
}
}
What line of code should replace the missing statement to make this program
compile?
A. import java.io.*; B. include java.io.*;
C. import java.io.PrintWriter; D. No statement required

21. The ……………………… class provides the capacity to read primitive data types from an input
stream.
A. pushbackInputStream B. DataInputStream
C. BufferedInputStream D. PipeInputStream
22. Which of the following is/are the methods of the DataOutputStream class.
i) void writeChar(intV) ii) void writeLong(longV)
iii) void writeInt(intV) iv) int size( )

A. ii, iii and iv only B. i, ii and iii only


C. i, ii and iv only D. All i, ii, iii and iv
23. What is the output of the following program?
import java.util.*;

public class priorityQueue


{
public static void main(String[] args)
{
PriorityQueue<Integer> queue =
new PriorityQueue<>();
queue.add(11);
queue.add(10);
queue.add(22);
queue.add(5);
queue.add(12);
queue.add(2);

while (queue.isEmpty() == false)


System.out.printf("%d ", queue.remove());

System.out.println("\n");
}
}

A. 11 10 22 5 12 2 B. 2 12 5 22 10 11
C. 2 5 10 11 12 22 D. 22 12 11 10 5 2
24. What is the output of following Java Program?
import java.util.ArrayList;
class Demo {
public void show()
{
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(4);
list.add(7);
list.add(1);
for (int number : list) {
System.out.print(number + " ");
}
}
} public class Main {
public static void main(String[] args)
{
Demo demo = new Demo();
demo.show();
}
}

A. Compilation Error B. 4 7 1
C. 1 4 7 D. None
25. What is the Output of following Java Program?
import java.util.LinkedList;
class Demo {
public void show()
{
LinkedList<String> list = new LinkedList<String>();

System.out.println(list.getClass());
}
} public class Main {
public static void main(String[] args)
{
Demo demo = new Demo();
demo.show();
}
}

A. class java.util.LinkedList B. String


C. Compiler Error D. None

Theory

1. What is polymorphism and what is its significance?


2. How to find out state of a thread which is joined with its child?
3. Develop User defined exception class
4. How can we customize the serialization process?
5. Why labeled loops are required. Explain with any real time example

SQL

1. Write a SQL query to fetch employee names who are under project id p1

2. Write a query to fetch employee names and projectId records. Return employee details even if
the

employee not allocated project yet.

3. Write a SQL query to fetch all the Employee name and his/her manager name

4. Write a SQL query to fetch all employee records from EmployeeDetails table who have a project id

record in EmployeeSalary table.

5. Write SQL query to read nth record to (n + 15)th record from table.

Table - EmployeeDetails
EmpId FullName ManagerId DateOfJoining
121 John Snow 321 01/31/2014
321 Walter White 986 01/30/2015
421 Kuldeep Rana 876 27/11/2016
Table - EmployeeSalary
EmpId Project Salary
121 P1 8000
321 P2 1000
421 P1 12000

Das könnte Ihnen auch gefallen