You are on page 1of 15

S.

No Question A B C D Answer
What is the output for the below code ?
<pre>
public class A {
public A(int i){
System.out.println(i);
}
}
1. public class B extends A{
2. public B(){ Compilation fails Compilation fails
1 3. super(6); <pre>0</pre> <pre>6</pre> due to an error due to an error D
4. this(); on lines 3 on lines 4
5. }
6. }
public class Test{
public static void main (String[] args){
B b = new B();
}
}
</pre>
Given:
<pre>
1.public class StrBoo {
2. public static void main(String[] args) {
3. List lst = new ArrayList();
4. lst.add(new Integer(12).intValue());
5. lst.add(new String("foo")); throws
2 6. lst.add(new Boolean(true)); 12 foo true 12 foo TRUE Compilation fails. java.lang.ClassCa D
7. Arrays.sort(lst.toArray()); stException
8. for (int i = 0; i < lst.size(); i++) {
9. System.out.print(lst.get(i).toString());
10. }
11. }
12.}</pre>
What is result?
Given:
<pre>
1.public class ExpTest{
2. public static void main(String[] args){
3. try { testException(); }
4. catch (RuntimeException ex) {
System.out.print("runtime "); }
5. System.out.print("end ");
testException
6. } Compilation testException testException
3 Exception C
7. static void testException() throws fails. Exception end runtime end
runtime end
RuntimeException {
8. try {
9. System.out.print("testException ");
10. throw new RuntimeException();
11. }
12. catch (Exception ex) {
System.out.print("Exception "); }
13. }
Given:
<pre>
public class SimpleDouble {
public static void main(String[] args){ <pre>|
double d = 456.6537; <pre>| 456.66| 456.65| <pre>|456.653| Compilation
4 A
System.out.printf("|%7.2f| ", d); |456.66|</pre> |456.653|<pre |456.65|</pre> fails.
System.out.printf("|%5.2f| ", d); >
}
}</pre>
What is output?
<pre>public class Test {
public static void main(String[] args){
try { Unreachable
} catch (NullPointerException e1) { catch block for
System.out.print("a"); NullPointerExce
} catch (Exception e2) { ption. This
5 c ab bc B
System.out.print("b"); exception is
} finally { never thrown
System.out.print("c"); from the try
} statement body
}
}</pre><br> What is output?
<pre>public class Num {
int squares = 21;
public static void main(String[] args) {
new Num.go();
}
void go() {
6 <pre>23</pre> <pre>43</pre> <pre>32</pre> <pre>65</pre> A
incr(++squares);
incr(++squares);
System.out.println(squares);
}
void incr(int squares) { squares += 10; }
} </pre>
Which Raju class properly represents the class Raju{ class Raju { class Raju { class Raju
7 B
relationship "Raju has a best friend who is a private private Rat private Rat; extends Rat { }
What is the output for the below code ?
<pre>
public static void main(String[] args) {
int i1=1;
switch(i1){
case 1:
8 System.out.println("one"); one two three one two one compiler error A
case 2:
System.out.println("two");
case 3:
System.out.println("three");
}
}</pre>
What is the output for the below code ?
<pre>
public enum Tester {
BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19,
45);

private int hh;

private int mm;

Tester(int hh, int mm) { Compile Error -


assert (hh >= 0 && hh <= 23) : "Illegal hour."; an enum
assert (mm >= 0 && mm <= 59) : "Illegal mins."; <pre> 7:30 cannot be <pre> 12:50 <pre> 19:45
9 B
this.hh = hh; </pre> instantiated </pre> </pre>
this.mm = mm; using the new
} operator.

public int getHour() {


return hh;
}

public int getMins() {


return mm;
}

public static void main(String args[]){


What is the output for the below code ?
<pre>
public class B {

public String getCountryName(){


return "USA";
}

public StringBuffer getCountryName(){ Compile with Runtime


10 USA UK A
StringBuffer sb = new StringBuffer(); error Exception
sb.append("UK");
return sb;
}
public static void main(String[] args){
B b = new B();

System.out.println(b.getCountryName().toString(
));
What is the output for the below code ?

<pre>
public class A {
public A() {
System.out.println("A");
}
}
public class Test {
public static void main(String... args) throws
java.io.NotSerializ None of the
11 Exception { AA A C
ableException Above
A a = new A();
ObjectOutputStream save = new
ObjectOutputStream(new
FileOutputStream("datafile"));
save.writeObject(a);
save.flush();
ObjectInputStream restore = new
ObjectInputStream(new
FileInputStream("datafile"));
A z = (A) restore.readObject();
Map Map m = Map m =
None of the
12 HashMap can be synchronized by _______ ? m=Collections.s hashMap.sync Collection.synchr A
above
ynchronizedMa hronizeMap(); onizeMap(hashM
What is the output for the below code ?
<pre>
public class Test {
public static void main(String... args) {

Pattern p = Pattern.compile("a{1,3}b?c*");
NullPointerExce
13 Matcher m = p.matcher("aaab"); True compiler error False A
ption
boolean b = m.matches();
System.out.println(b);

}
}
</pre>
<pre>
What is the output for the below code ?

public class Test {


public static void main(String... args) {

Console con = System.console();


boolean auth = false;
Compile Error :
if (con != null)
No
{ NullPointerExcept
14 null readPassword( It works properly C
int count = 0; ion
) method in
do
Console class.
{
String uname = con.readLine(null);
char[] pwd = con.readPassword("Enter %s's
password: ", uname);

con.writer().write("\n\n");
} while (!auth && ++count < 3);
}

}
} </pre>
What is the output for the below code ?
<pre>
public class Test {
static { int a = 5; }
public static void main(String[] args){ Compile with Runtime
15 <pre>5</pre> <pre>0</pre> B
System.out.println(a); error Exception
}
}
</pre>

Which of the following modifier is used to


16 strictfp native transient volatile C
prevent a property from being serialized ?
A class or interface that operates on none of the
17 TypeWrapper Collection Generic C
parameterized type is called ? above
_____ is a process by which the value of object is
18 Autoboxing Auto-Unboxing Encapsualtion Abstraction B
automatically extracted from a type wrapper?
19 In Java, each thread has its own ________, in main() method JVM Call stack Memory C
Variables final variable Arrays in java are All arrays
20 Which of the following statements are incorrect? declared as must be implemented as contain an A
final occupy initialized at an object. attribute-length
21 Which of these cannot be declared static? class object method method B
Platform independent code file created from
22 JRE JVM Complier Applet B
Source file is understandable by
23 Who is called as father of Java Programming Larry Page Bjarne James Gosling None of these C
In chained exception which method relates one
24 getCause() initCause() setCause() chainCause() B
exception with another exception ?
25 What is the base class for all Exception ? java.lang.Excep java.lang.Thro java.lang.Runtim java.lang.Error B
Member Static Variables Static Final Member
26 Interface can only have ... elements and and Static Variables and Elements , C
Methods. Methods. Instance Method Instance
27 In what order the elements of a HashSet are Random Order Insertion Natural Sorting Inverse Natural A
If we try to add duplicate key to the HashMap, It will throw an It won't add The new element Compiler will
28 C
What will happen ? exception. the new will replace the identify the
What is the result?
<pre>
class Circus {
public static void main(String[] args) {
int x = 9;
int y = 6;
for(int z = 0; z < 6; z++, y--) {
if(x > 2) x--;
label:
if(x > 5) { <pre>8 Compilation
29 <pre>8</pre> <pre>8 7 6</pre> D
System.out.print(x + " "); 7</pre> fails.
--x;
continue label;
}
x--;
}
}
}
<pre>
<pre>
0. public class testparse {
1. public static void format(String str) {
2. try {
3. float flt = Float.parseFloat(str);
4. } catch (NumberFormatException nfe) {
5. flt = 0;
By adding
6. } finally { By adding "static
no need of "static float flt By defining "flt"
30 7. System.out.println(flt); float flt = 0;" B
correction = 0;" before in every block .
8. } inside try block.
line 1
9. }
10.public static void main(String[] args) {
11.format("illlegal");
12.}}
<pre><br>
How can we correct the above code?

31 The SQL keyword(s) ________ is used with LIKE IN IN and NOT IN NOT IN A
Which of the following do you need to consider
32 Data types Primary keys Default values All of the above D
when you make a table in SQL?
Which statement in SQL allows us to change the
33 ALTER UPDATE CREATE SELECT A
definition of a table is?
ALTER TABLE ALTER TABLE ALTER TABLE ALTER TABLE
student_grades student_grade student_grades student grades
34 Which statement explicitly names a constraint? ADD FOREIGN s ADD ADD CONSTRAINT ADD NAME C
KEY CONSTRAINT student_id_fk student_id_fk
(student_id) NAME = FOREIGN KEY FOREIGN KEY
SELECT SUBSTR( SELECT SELECT SELECT
Which SELECT statement will the result ‘ello
35 ‘Hello World’,1) INITCAP(TRIM LOWER(SUBSTR(‘ LOWER(TRIM D
world’ from the string ‘Hello World’?
FROM dual; (‘Hello World’, Hello World’, 1, 1) (‘H’ FROM ‘Hello
You need to display the last names of those SELECT SELECT SELECT
SELECT last_name
employees who have the letter “A” as the last_name last_name last_name FROM
FROM EMP
36 second character in their names. FROM EMP FROM EMP EMP WHERE last A
WHERE last name
Which SQL statement displays the required WHERE WHERE last name LIKE
=’_A%’;
results? last_name LIKE name =’*A%’; ‘*A%’;
You define a multiple-row subquery in the The main query The main The main query The main query
37 WHERE clause of an SQL query with a executes with query executes executes with all fails because the D
comparison operator "=". What happens when the first value with the last the values multiple-row
Group Group Group functions Group functions
What is true of using group functions on functions on functions on on columns on columns
38 A
columns that contain NULL values? columns ignore columns cannot be include NULL
NULL values. returning accurately used values in
a schema a subquery another name for a subquery that
39 Which best describes an inline view? D
object that can a view that is part of the
Evaluate these two SQL statements:
<pre>
SELECT last_name, salary, hire_dateFROM
EMPLOYEES ORDER BY salary DESC;<br>
SELECT last_name, salary, hire_dateFROM
EMPLOYEES ORDER BY 2 DESC;<br>
What is true about them?
A. The two statements produce identical results.
40 B. The second statement returns a syntax error. A B C D A
C. There is no need to specify DESC because the
results are sorted in descending order by
default.
D. The two statements can be made to produce
identical results by adding a column alias for
the salary column in the second SQL statement.
</pre>
Which of the following results are true, when a
ROLLBACK statement is issued to the database,
the transaction has ended?
<pre>
A. All work done by the transaction is undone, as
41 A B C D C
if it hadn't been issued.
B. Any locks acquired by the transaction are
released.
C. Both A & B
D. None of the above
In which subprogram a RETURN statement does None of the
42 In Procedures In Functions Both A & B A
not return a value and so cannot contain an above
When three or more AND and OR conditions are Both IN and NOT
43 NOT IN only. LIKE only. IN only. D
combined, it is easier to use the SQL keyword(s): IN.
Find all the cities with temperature, condition SELECT * FROM SELECT * SELECT * FROM SELECT * FROM
44 and humidity whose humidity is in the range of weather FROM weather weather WHERE weather WHERE C
63 to 79 WHERE WHERE humidity humidity NOT
What is the meaning of LIKE '%0%0%' in a SQL Feature begins Feature ends Feature has more Feature has two
45 D
statement with two 0's with two 0's than two 0's 0's in it, at any
Enumerations Enumerations Enumerations Enumerations
Which of the following statement is not correct
46 can have can have are instantiated can implement C
about an Enumerations class ?
Constructors. instance using new Interfaces.
Process of converting an object into a sequence Deserializatio
47 Serialization Synchronization Externalization A
of bytes which can be persisted is called ? n
<pre>String x = new String("xyz");
String y = "abc";
48 <pre>2</pre> <pre>3</pre> <pre>4</pre> <pre>5</pre> C
x = x + y;</pre><br/>How many String objects
have been created?
What will be the output of the
program?<br/><pre>String a = "ABCD";
String b = a.toLowerCase();
49 abcd ABCD dccd dcba A
b.replace('a','d');
b.replace('b','c');
System.out.println(b);</pre>
50 Which will contain the body of the thread? run() start() stop() main() A

You might also like