oracle-placementpaper-4
1. What is the output of the following program

main()
{
int i = 5;
printf("%d\n", i++ * i--);
}

(A) 25 
(B) 24 
(C) 20 
(D) 30


2. What is the output of the following program

main()
{
char ch='a';
printf("%d ",ch);
printf("%d\n",((int)ch)++);
}

(A) 97 98
(B) 97 
(C) 97 97 
(D) compilation error


3. What does the following program do ?

int main()
{
int i;
int array1[10], array2[10] ;
int *ep, *ip2 = &array2[0];
int *ip1 = &array1[0];
for(ep = &array1[9]; ep >= ip1; ep--)
*ep = *ip2++ ;
}

(A) copies array1 to array2
(B) copies array2 to array1
(C) copies array1 to array2 in reverse order
(D) copies array2 to array1 in reverse order


4. what does the following program do ?

#include
int main()
{
char string[100];

char *p;

gets(string);
for(p = string; *p != '\0'; p++)
;

printf("%d", p - string);
}

(A) prints the memory used by "string"
(B) prints the character values of "string"
(C) prints the length of "string"
(D) errors out.

5. What is the output if the input to following program is, 
INDIA DEVELOPMENT CENTRE 

#include 
int trail(char *line, int max);
main()
{
char p[100];
printf("%d",trail(p,10));
}
int trail(char *line, int max)
{
int nch = 0;
int c;
max = max - 1; 

while((c = getchar()) != EOF)
{
if(c == '\n')
break;

if(nch < max)
{
*(line + nch) = c;
nch = nch + 1;
}
}

if(c == EOF && nch == 0)
return EOF;

*(line + nch) = '\0';
return nch;
}

(A) 22
(B) 24
(C) 10
(D) 9


6. What is the output of the following program :

main()
{ int i=1 ;
for (;;);
{
if(i==1)
{
printf("%d",i);
exit();
}
}
}

(A) Will print 1 and exit.
(B) Compilation error .
(C) will loop infinitely .
(D) None of the above .

7. What is the output, if 5 is the input for 'i' ?

main()
{
int *i;
i =(int *)malloc(10);
printf("Enter the value for i:");
scanf("%d",i);
++*i--;
printf("value of i :%d", *i);
}

(A) value of i :4
(B) value of i :6
(C) value of i :5
(D) value of i :1

8. What is the output of the following program ?

const int n = 7;
int a[n];
main()
{
int i,k=8;
for (i=0;i
void main()
{
void recurse(int);
int i = 5;
recurse(i);
}
void recurse(int u)
{
if (u > 0)
recurse(u-1);
printf("%d ",u);
}

(A) 1 2 3 4 5 
(B) 5 4 3 2 1
(C) 0 1 2 3 4 5 
(D) 5 4 3 2 1 0 

12. What is the output of the following program

#include 
void main()
{
void assign(int[]);
int i[5],a=0;
for (a = 0;a < 5;a++)
i[a] = 10;
assign(i);
for (a = 0; a< 5 ;a++)
printf(" %d",i[a]);
}
void assign(int y[])
{
int b = 1;
y[b] = 5;
}

(A) 5 10 10 10 10
(B) 10 5 10 10 10
(C) 10 10 10 10 10
(D) Compilation Error

13. What is the output of the following program

#include
void main()
{
char *p ;
p = (char*)malloc(100);
strcpy(p,"Oracle India");
(p[5] == 'l') ? printf("Oracle") : printf("India");
}

(A) Oracle 
(B) India
(C) Compilation Error
(D) Run-Time Error (Core Dump)

14. What is the output of the following program

#include 
void main()
{
int a=5,b,i;
int func(int y);
for(i = 0;i < 5;i++)
{
a = b = func(a);
printf("%d ",b);
}
}

int func(int y)
{
static int x = 0;
x++;
y = y + x;
return(y);
}

(A) 6 7 8 9 10
(B) 5 7 9 11 13
(C) 6 8 10 12 14 
(D) 6 8 11 15 20

15. What is the output of the following program

#include 
void main()
{
char i;
for(i=0;i<=256;i++)
printf("%d",i);
}

(A) Endless Loop
(B) Compilation Error
(C) Run-Time Error
(D) Ascii Characters from 1-256

16. NO_DATA_FOUND Exception is raised only

(A) When the Where clause of an explicit cursor does not match any rows
(B) for SELECT ..INTO statements, when the where clause of the query does not match any rows
(C) for update/delete statement , when the WHERE clause does not match any rows
(D) All the Above 

17. Consider the following PL/SQL Code

DECLARE
Cursor c_emp is
select * 
from emp1
where dno = 10 
for update ; 
v_empinfo c_emp%rowtype ;
BEGIN
FOR v_empinfo in c_emp LOOP 
update emp1 
set salary = salary * 10 
where current of c_emp ;
commit ;
END LOOP ;
END ;
/

Data in EMP Table : 

Empno Name Sal Dno

100 abc 1000 10
200 def 2000 10
300 ghi 3000 20

What is the output ?

(A) (Empno,Sal) -> (100,10000),( 200,20000),(300,30000) 
(B) (Empno,Sal) -> (100,10000),(200,20000),(300,3000)
(C) Error : "Use of Where Current of Restricted "
(D) Error : "Fetch Out of Sequence "

18. Consider the following PL/SQL code. 

declare
v_char varchar2(3) := 'ABCD';
begin
dbms_output.put_line('Value of v_char ' || v_char);

exception
when others then
dbms_output.put_line('Exception Captured');
end;
/


What is the output ?

(A) "Value of v_char ABCD"
(B) "Exception Captured"
(C) ORA-06502: PL/SQL: numeric or value error 
(D) ORA-1458-invalid length inside variable character string

19. Consider the following PL/SQL Code

declare
empno emp1.empno%type ;
begin

select empno
into empno
from emp1
where sal > 1000
and rownum < 2 ;

update emp1
set sal = sal + 1000
where empno = empno ;

exception when others then
dbms_output.put_line('Exception Raised' );


end ;
/

Data in Emp Table :

Empno Name Sal 
100 ABC 1000
200 DEF 2000
300 GHI 3000

What will be the output ?

(A) (Empno,Sal) -> (100,1000,200,3000,300,4000)
(B) (Empno,Sal) -> (100,1000),(200,3000),(300,3000)
(C) (Empno,Sal) -> (100,2000),(200,3000),(300,4000)
(D) Error: Invalid usage of variable name which is same as column name

20. Consider the following PL/SQL Code

Create or replace procedure Test_Proc(
p_empno in number ,
p_dno in number ,
p_sal in out number ) is
v_tempvar number ;
begin 
if p_sal < 1000 then
p_dno = 20 ;
p_sal = p_sal+ 1000 ;
end if ;
end ;


When the above procedure is compiled , it will 

(A) Create procedure Test_Proc ,if one already exists replace it. 
(B) Error : Expression 'P_DNO' cannot be used as an assignment target 
(C) Error : 'P_SAL' cannot be used as both "In" and "Out" 
(D) Warning : v_tempvar not used anywhere 

21. Identify the value of l_result at the end of the following PL/SQL block:

DECLARE 
l_var_1 NUMBER := 1;
l_var_2 CHAR(4) := 'Test';
l_result VARCHAR2 (20);
BEGIN
DECLARE
l_var_1 VARCHAR2(10) := 10;
l_var_3 NUMBER := 2;
BEGIN
l_result := l_var_3 * l_var_1;
END;
l_result := l_var_2 || l_result || l_var_1;
dbms_output.put_line (l_result);
END;


(A) Test21
(B) Test2010
(C) Test201
(D) Test210 

22. Consider the following PL/SQL block.

DECLARE 
l_var NUMBER := 1;
BEGIN
IF (l_var = 1) THEN
GOTO Jump;
END IF;
IF (l_var < 5) THEN
<>
dbms_output.put_line (l_var);
END IF;
END;

Which of the following statements is correct?

(A) Usage of labels is invalid in PL/SQL. 
(B) GOTO cannot branch into an IF statement
(C) GOTO is not a valid syntax.
(D) (A) and (C) are correct statements.

23. Consider the following PL/SQL block.

DECLARE
l_var1 NUMBER := &a;
l_var2 NUMBER := &b;
Data_problem EXCEPTION;
BEGIN
BEGIN
IF (l_var1 > l_var2) THEN
RAISE NO_DATA_FOUND;
ELSE
RAISE Data_Problem;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('No Data');
WHEN Data_Problem THEN
RAISE Data_problem; 
END;
EXCEPTION
WHEN Data_problem THEN
dbms_output.put_line ('Data Problem'); 
END;

Identify which of the following statements is/are correct.

(A) Output printed is 'No Data' when a > b .
(B) Exception cannot be used to move from inner to outer block.
(C) Output printed is 'Data Problem' when b > a .
(D) Statements A and C are correct.

24. Employee table has records of 10 employees. 
Execution of the following PL/SQL block given below will result in :

DECLARE
CURSOR C1 IS
SELECT name, basic+hra salary
FROM employee ;
Incentive NUMBER;
l_name VARCHAR2(30);
l_salary NUMBER;
BEGIN
LOOP
Fetch c1 INTO l_name, l_salary;
EXIT WHEN c1%NOTFOUND OR
c1%ROWCOUNT = 9 ;
Incentive := l_salary * 0.1 ;
END LOOP;
close c1;
dbms_output.put_line ('Name - ' || l_name);
dbms_output.put_line ('Incentive =' || Incentive);
END;


(A) Error as alias cannot be used in cursor.
(B) Name & Incentive of nine employees will be printed. 
(C) Error as %NOTFOUND & %ROWCOUNT cannot be used with explicit cursors.
(D) Error - Invalid cursor

25. Consider the procedure given below:

PROCEDURE calc_bonus (salary IN INTEGER, gross_salary IN OUT NUMBER, 
bonus OUT NUMBER) IS
BEGIN
IF (salary > 1000) THEN 
bonus := Salary * .1 ; -- statement 1
ELSE
salary := Salary * 2; -- statement 2
bonus := salary * 0.1 ; -- statement 3
END IF;
gross_salary := Salary * 2 ; -- statement 4
END;

(A) No errors are there in the PL/SQL block
(B) Statements 1 and 3 will result in error.
(C) Statement 2 will result in error.
(D) Statements 1, 2 and 3 will result in error.

26. Consider the following data

TABLE A TABLE B
COL1 COL1
------ -------
10 15
20 20
30 25
40 30
50 35
60 40
70 45
80 50
10 35
100 60
65
30
80
90
100


select count(*)
from (select A1.col1 col1
from A A1, A A2
where A1.col1 = A2.col1
UNION ALL
select A.col1 col1
from A, B
where A.col1(+) = B.col1 );

What would be output of the above SQL query?

(A) 25 
(B) 27 
(C) 29 
(D) error

27. Consider the following DDL

create table emp(
empno number,
name char(30),
sal number,
deptno number,
manager number)

create table dept(
deptno number,
name char(30),
location char(30))


i) create view view1 as
select location, count(empno) emp_count
from emp, dept
where emp.deptno = dept.deptno
group by location;

ii) create view view2 as
select empno, name, location
from emp, dept
where emp.deptno = dept.deptno;

iii) create view view3 as
select *
from emp, dept;

Which is the correct view definition ?

(A) i 
(B) i and ii
(C) ii and iii
(D) All

28. What is the output of the SQL statement

select floor((ceil(-0.42) - abs(round(-0.64)))/2) from dual;

(A) -2 
(B) -1 
(C) 0 
(D) 1

29. Consider the following data 

Table STUDENT

Name subject status
----------- --------------- --------
Student1 Sub1 P
Student1 Sub2 F
Student2 Sub1 P
Student3 Sub2 F
Student4 Sub1 F
Student4 Sub2 P
Student5 Sub1 P
Student5 Sub2 P
Student6 Sub1 F
Student6 Sub2 F

i) select * from student
where status = 'P' OR status = 'F' AND subject = 'Sub1';

ii) select * from student
where (status = 'P' OR status = 'F') AND subject = 'Sub1';

iii) select * from student
where subject = 'Sub1' AND status = 'P' OR status = 'F';

iv) select * from student
where status = 'P' OR (status = 'F' AND subject = 'Sub1');


Which statements would produce same output

(A) i & ii 
(B) ii & iii 
(C) iii & iv 
(D) i & iv 

30. Consider the following DML operation along with table data from above question

i) update student s1
set s1.status = 'P'
where s1.subject = 
( select distinct(s2.subject)
from student s2
where s1.name = s2.name );

ii) delete from student s1
where status > 'F'
and s1.name not in 
( select s1.name
from student s2
where s2.subject = 'Sub2');

iii) update student s1
set s2.status = 'P' 
where s1.subject in 
( select s2.subject
from student s2
where s2.status = 'F');

Which statement(s) are incorrect/errors out:

(A) i & ii
(B) ii & iii
(C) i & iii
(D) i, ii & iii


Answers:a,d,d,c,d,c,d,c,a,a,c,b,b,d,a,b,d,c,c,b,c,b,d,d,c,b,a,b,d,c
--------------------------------------------------------------------------------------------
1. What is the output of the following program
class ExceptionClass1 extends Error {
public String toString() {
return "ExceptionClass1";
}
}

class ExceptionClass2 extends Exception {
public String toString() {
return "ExceptionClass2";
}
}

public class ExceptionClassesTest {
private static final int CLASS1 = 10;
private static final int CLASS2 = 20;

public static void main( String[] args ) {
int param = Integer.parseInt(args[0]);
try {
exceptionClassTest( param );
}
catch(Throwable t) {
System.out.println("" + t );
}
}
public static void exceptionClassTest(int param) throws ExceptionClass2 {
try {
if( param == CLASS1 ) throw new ExceptionClass1();
if( param == CLASS2 ) throw new ExceptionClass2();
}
catch( Exception ex ) {
System.out.println("" + ex );
throw (ExceptionClass2)ex;
}
}
}

main()
{
int i = 5;
printf("%d\n", i++ * i--);
}

If you compile the above program and do the following, what is the output ?

1. java ExceptionClassesTest 10
2. java ExceptionClassesTest 20
3. java ExceptionClassesTest 30

(A) Cannot do the above because the program will give compilation error ‘unreported exception java.lang.ExceptionClass1; declared to be thrown'
(B) ExceptionClass1( twice ), ExceptionClass2 ( twice ), No output
(C) ExceptionClass1( once ), ExceptionClass2( twice ), No output
(D) Cannot do the above because the program will give compilation error 'incompatible types found : ExceptionClass1, required: java.lang.Throwable'


2. When trying to establish a JDBC connection, it fails with the message “Driver not found”.

This is due to

(A) The DriverManager class is not found
(B) The JDBC driver is not registered
(C) The JDBC driver does not exist in the CLASSPATH
(D) The Connection class is not found


3. 

public class Select {

public static void main (String args[]) {
String url = "jdbc:oracle://Carthage.imaginary.com/ora";
Connection con = null;

try {
String driver = "com.imagiary.sql.oracle.OracleDriver";
Class.forName(driver).newInstance();
}
catch (Exception e) {
System.out.println("Failed to load Oracle Driver.");
return;
}

try {
con = DriverManager.getConnection(url, "borg", "");
Statement select = con.createStatement();
ResultSet result = select.executeQuery("SELECT DATE_OF_JOINING from EMP");

While (result.next()) {
System.out.println("The date of joining is " + result.getString(1));
}
}
}
}

Note: the column DATE OF JOINING is not null and it always has a value.

What would be the output of this code?

(A) This code does not compile
(B) "The date of joining is 01-JUN-1999". (The sample date fetched by the SQL stmt)
(C) The code complies but results in run-time exception
(D) "The date of joining is ". ( The date is null)


4. As far as handling null values in JAVA and SQL is concerned which of the following statements is wrong?

(A) For Java Objects SQL NULL maps to JAVA NULL
(B) While using the method getInt( ), the JAVA NULL maps the SQL NULL 
(C) a Java ResultSet has no way of representing a SQL NULL value for any numeric SQL column
(D) Call to getInt() could return some driver attempt at representing NULL, most likely 0.


5. As per the JDBC Specification for SQL to Java Datatype Mappings, which of the following statements is correct?


(A) The SQL datatype FLOAT maps to the Java datatype float
(B) The SQL datatype FLOAT maps to the Java datatype long
(C) The SQL datatype FLOAT maps to the Java datatype double
(D) The SQL datatype FLOAT maps to the Java datatype int


6. Which of the following is not valid array declarations/definitions?


(A) int iArray1[10];
(B) int iArray2[];
(C) int iArray3[] = new int[10];
(D) int []iArray5 = new int[10];


7. As per the JDBC Specification for Java to SQL Datatype Mappings, which of the following statements is correct?

(A) The Java datatype float maps to the SQL datatype REAL
(B) The Java datatype float maps to the SQL datatype DOUBLE
(C) The Java datatype float maps to the SQL datatype INTEGER
(D) The Java datatype float maps to the SQL datatype SMALLINT


8. Which of the following is a legal return type of a method overloading the following method:

public void add(int a) { …. }

(A) void
(B) int
(C) Can be anything
(D) short

9. Which of the following is not one of the methods for the class DriverManager?

(A) static public synchronized Connection getConnection ( String url, Properties info) throws SQLException
(B) static public synchronized Connection getConnection ( String url,Strng user, String password) throws SQLException
(C) static public synchronized Connection getConnection ( String url ) throws SQLException
(D) static public synchronized Connection getConnection ( String url, Strng user, String password, Properties info) throws SQLException


10. Which of the following is false with respect to updateable result sets 

(A) The select should pertain to a single table and should include the primary key columns
(B) JDBC drivers are not required to support updateable result sets
(C) If the driver does not support updateable result set, it will always throw an exception
(D) If the driver does not support updateable result set, it will issue a SQLWarning and assigns the result set to a type it can support.


11. Which of the following is not true about jsp:forward

(A) This allows the request to be forwarded to another JSP, a servlet or a static resource.
(B) The resource to which the request is being forwarded should be in the same context as the JSP dispatching the request
(C) Execution in the current JSP stops when it encounters jsp:forward tag
(D) The output stream need not be buffered and it can contain some output written to it.

12. A session has been created by the client. If the client does not continue the session within a specified time, which of the following will not happen


(A) the server will expire the session and delete all data associated with the session
(B) the server will expire the session but the data associated with the session are retained
(C) The session key is invalidated
(D) The old session key is not associated with any session


13. What is the output of the following program

class getBoolValues {
public static void main (String args[]) {
boolean a = true;
boolean b = false;
boolean c = a ^ b;
boolean d = (!a & b) | (a & !b)
System.out.println(" a ^ b = " + c);
System.out.println(" !a&b|a&!b = " + d);
}
}

(A) The code does not compile.
(B) a ^ b = true 
!a&b|a&!b = true
(C) The code compiles but raises an exception during runtime.
(D) a ^ b = true
!a&b|a&!b = false



14. What is the output of the following program

class questionA {
public static void main ( String args[] ) {
int i, k;
i = 10;
k = i < 0 : -i ? i; // get absolute value of i
System.out.print("Absolute value of ");
System.out.println(i + " is " + k);
i = -10;
k = i < 0 ? -i : i; // get absolute value of i
System.out.print("Absolute value of ");
System.out.println(i + " is " + k);
}
}

(A) The code does not compile.
(B) Absolute value of 10 is 10
Absolute value of -10 is 10
(C) The code compiles but raises an exception during runtime.
(D) Absolute value of 10 is 10
Absolute value of -10 is -10

15. What is the output of the following program

class questionB {
static public void main ( String args[] ) {
char Que[ ] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
byte b = (byte) 0xf1;
System.out.println("b = 0x" + Que[ ( e >> 4) & 0xf ] + Que[ e & 0x0f ] );
}
}

(A) 0xf1
(B) 0xff
(C) 0xf0
(D) 0x0f



16. What is the output of the following program

class questionC {
int a;
public int c;
private int c;

void setc(int i) {
c = i;
}

int getc() {
return c;
}
}

class printQuestionC {
public static void main ( String args[ ] ) {
questionC qc = new questionC( );
qc.a = 10;
qc.b = 20;
qc.c = 100;
qc.b = qc.a + qc.c;
System.out.println ( "a, b and c : " + qc.a + ", " + qc.b + ", " + qc.getc());
}
}

(A) a, b and c : 10, 20, 100
(B) a, b and c : 10, 110, 100
(C) a, b and c : 10, 110,
(D) The code does not compile.


17. Which of the following is not true about serialization 

(A) Only an object that implements the Serializable interface can be saved and restored
(B) The Serializable interface defines no members
(C) transient variables can be saved by the serialization facilities
(D) static variables are not saved by the serialization facilities


18. What is the output of the following program ? 

class Promote {
public static void main ( String args[ ] ) {
byte b 42;
char c = 'a';
short s = 1-24;
int i = 50000;
float f = 5.67 f;
double d = .1234;
double resuot = (f * b) + (i / c) - (d * s);
System.out.println("Result = " + result);
}
}

(A) The code does not compile.
(B) The final result of the expression is a double
(C) The final result of the expression is a float
(D) The final result of the expression is an int


19. Consider the following Java Code

public class Alias {
int i;
Alias(int ii) { i = ii; }
public static void main ( String [ ] args ) {
Alias x = new Alias(7);
Alias1 y = x;
System.out.println("x : " + x.i);
System.out.println("y : " + y.i);
x.i++;
System.out.println("x : " + x.i);
System.out.println("y : " + y.i);
}
}

What will be the output ?

(A) The code does not compile
(B) The code compiles but gives runtime exception
(C) x = 7
y = 7
x = 8
y = 7
(D) x = 7
y = 7
x = 8
y = 8

20. Consider the following Java Code

public class Test {
public static void main (String args []) {
int age;
age = age + 1;
System.out.println("The age is " + age);
}
}

What will be output of the above code?

(A) Compiles and runs with no output
(B) Compiles and runs printing out The age is 1
(C) Compiles but generates a runtime error
(D) The code does not compile


21. What is the result of the executing the following code, using the parameters 4 and 0 ?

public void divide(int a, int b) {
try {
int c = a / b;
} catch (Exception e) {
System.out.print("Exception ");
} finally {
System.out.println("Finally");
}


(A) Prints out: Exception Finally
(B) Prints out: Finally
(C) Prints out: Exception
(D) No output 


22. Consider the following Java code.

import java.util.*;
import java.sql.*;

public class t6{
public t6(){}
public t6(String temp){System.out.println("In constructor of t6"+temp); }
public static long f(int n){
if (n<=2) return 1;
else
return (f(n-1)+f(n-2));
}
public static void main(String args[]){
System.out.println(args[0]+"th Fibonacci number is " + f(Integer.parseInt(args[0])));
}
}

import java.util.*;
import java.sql.*;

public class t7 extends t6{
public t7(){}
public t7(String temp){System.out.println("In constructor of t6"+temp); super(temp); }
public static void main(String args[]){
System.out.println(args[0]+"th Fibonacci number is " + f(Integer.parseInt(args[0])));
}
}

What would be the output for executing t7?

(A) The code does not compile
(B) The code compiles, but does not give an output
(C) The code compiles, but gives runtime error
(D) The code compiles and prints the n'th Fibonacci number.


23. In a constructor where can you place a call to the constructor defined in the super class ? 

(A) Anywhere
(B) The first statement in the constructor
(C) The last statement in the constructor
(D) You can't call super in a constructor

24. Which of the following will compile correctly

(A) short myshort = 99S;
(B) String name = 'Excellent tutorial Mr Green';
(C) char c = 17c;
(D) int z = 015;

25. Given the following variables which of the following lines will compile without error ? 

1. String s = "Hello";
2. long l = 99;
3. double d = 1.11;
4. int i = 1;
5. int j = 0;
6. j= i < 7 && d < 5 || d > 20 
B. c > 0 && d < 5 || d > 50 
C. c > 1 && d < 6 || d > 0 
D. c < 0 && d > 0 || d < 0 

27. Consider the following Java code

class E extends Exception { 


class ExceptHandle { 
public static void f() throws E { 

public static void main (String args[]) throws E { 
try { f(); 
System.out.println("no throw"); 

catch (E e) { 
System.out.println(" only handling"); 




Result of this program 

A. Compilation Error 
B. no throw 
C. only handling 
D. no throw only handling 

28. 

public class A 

public static void main(String[] args) 

System.out.println(new B().g()); 

private int f() 

return 2; 

int g() 

return f(); 



class B extends A { 
public int f() { 
return 1; 



What is the out put of the above code 

A. 1 
B. 2 
C. Null 
D. compilation error 

29. Consider the following java code

class AClass { 
static AClass createA() 

return new AClass(); 
} // createA() 


public class Tester { 
public static void main(String[] parms) { 
AClass aVar = null; 
System.out.println(aVar.createA().hashCode()); 



Compiling and Running of this will result in 

A. Compilation Error 
B. Run time exception (NullPointerException) because aVar is null so can not access null object members 
C. No compilation and runtime error. Returns null because aVar is null hence static member of this object will also return null 
D. No compilation and runtime error. Returns a value because when accessing a static member of an object, object value is not considered 


30. 

1 class XYZ { 
2 int i = 3; 
3 int j = this.i; 
4 static int k = this.i; 
5 static class A 
6 { 
7 static int l; 
8 } 

10 static A anA = new XYZ.A(); 
11 
12 A returnA1() 
13 { 
14 return this.anA; 
15 } 
16 static A returnA2() 
17 { 
18 return this.anA; 
19 } 
20 } 



Compile and Run this code will cause 

A. No Compilation error 
B. Compilation error at line 3 and 14 
C. Compilation error at line 4 and 18 
D. Compilation error at line 5 and 10 

Ans:d,a,c,a,d,c,b,d,c,c,b,b,c,a,c,c,c,a,c,c,d,a,d,a,c,c,b,b,d,c
--------------------------------------------------------------------------------------------1. Which of the following lines will compile without warning or error. 

A) float f=1.3; 
B) char c="a"; 
C) byte b=257; 
D)int i=10;

Answer: D



2. Which of the following statements are true? 

A) Methods cannot be overriden to be more private
B) Static methods cannot be overloaded
C) Private methods cannot be overloaded
D) An overloaded method cannot throw exceptions not checked in the base class

Answer: A

3. If you wanted to find out where the position of the letter v (ie return 2) in the string s 
containing "Java", which of the following could you use? 

A) mid(2,s); 
B) charAt(2); 
C) s.indexOf('v'); 
D) indexOf(s,'v');

Answer: C

4. Given the following declarations 

String s1=new String("Hello")
String s2=new String("there");
String s3=new String();

Which of the following are legal operations? 

A) s3=s1 + s2; 
B) s3=s1-s2; 
C) s3=s1 & s2; 
D) s3=s1 && s2

Answer: A

5. Which of the following will successfully create an instance of the Vector class and add an element? 
1) Vector v=new Vector(99); 
v[1]=99; 
2) Vector v=new Vector(); 
v.addElement(99); 
3) Vector v=new Vector(); 
v.add(99); 
4 Vector v=new Vector(100); 
v.addElement("99");

Answer: D

6.Which of the following is not valid array declarations/definitions?

A) int iArray1[10];
B) int iArray2[];
C) int iArray3[] = new int[10];
D) int []iArray5 = new int[10];

Answer: A

7.Assuming a method contains code which may raise an Exception (but not a RuntimeException), what is the correct way for a method to indicate that it expects the caller to handle that
exception:

A) throw Exception 
B) throws Exception 
C) new Exception 
D) Don't need to specify anything

Answer: B

8.Which of the following is a legal return type of a method overloading the following method:

public void add(int a) {…}

A) void 
B) int 
C) Can be anything
D) short

Answer: C

9.What class must an inner class extend:

A) The top level class 
B) The Object class 
C) Any class or interface 
D) It must extend an interface

Answer: C

10.What is the effect of adding the sixth element to a vector created in the following manner:

new Vector(5, 10);

A) An IndexOutOfBounds exception is raised. 
B) The vector grows in size to a capacity of 10 elements 
C) The vector grows in size to a capacity of 15 elements 
D) Nothing, the vector will have grown when the fifth element was added

Answer: C



11. What is the value returned by 

“abcd” instanceof Object
A) “abcd”
B) true
C) false
D) String

Answer: B

12. Which of the following are true about constructors?

A) A class inherits its constructors from its parent
B) The compiler supplies a default constructor if no constructors are provided for a class
C) All constructors have a void return type
D) A constructor cannot throw an exception

Answer: B

13. Which of the following are true about an unreachable object?

A) It will be garbage collected
B) Its finalize() method will be invoked
C) It can become reachable again
D) It has a null value

Answer: C

14. Which of the following must be true of the object thrown by a throw statement?

A) It must be assignable to the Throwable type
B) It must be assignable to the Error type
C) It must be assignable to the Exception type
D) It must be assignable to the String type

Answer: A

15. Can a null value e added to a List?

A) Yes
B) Yes, but only if the List is linked
C) Yes, provided that the List is non-empty
D) No

Answer: C

16. Which of the following are valid Java identifiers?

A) %id
B) @id
C) _id
D) #id

Answer: C

17.Which of the following are true about this variable declaration?
private static int I=3; 

A) The value of variable I may not be changed after it is assigned a value
B) Variable I may only be updated by a static method
C) The value of I is shared among all instances of the class in which it is declared
D) Variable I may be accessed within the static methods of other classes

Answer: C


18.

class Aliasing
{
private String s1;
private String s2;

public Aliasing( String a, String b )
{
s1 = a;
s2 = b;
}
public static void main( String[] args )
{
String s1 = new String("Hello");
String s2 = new String("World");
Aliasing a = new Aliasing( s1, s2 );
System.out.println( " Original " + a );
a.swap();
System.out.println( " After swaping " + a );
a.swap2( s1, s2 );
System.out.println( s1 + " " + s2 );
}
public String toString()
{
return s1 + " " + s2;
}
public void swap()
{
String s3 = new String();
s3 = s1;
s1 = s2;
s2 = s3;
}
public static void swap2( String s1, String s2 )
{
String s3 = new String("World");
s1 = s3;
s2 = s1;
s1 = s3;
}
}

If the above program is compiled and executed, what are the values of
s1 and s2 the end of the program ?

a. Hello, World
b. World, Hello
c. World, World
d. Hello, Hello

Answer : A


19.

class A {
A() { System.out.println("A"); }
}

class B {
static A a = new A();
{
System.out.println("C");
}
B() { System.out.println("B"); }
public static void main( String[] args ) {
System.out.println("D");
new B();
}
}

Consider the code given above, what is the output
of the following command

java B

a. A,C,D,B
b. D,A,C,B
c. A,D,C,B
d. No output, the code will give compilation errors

Answer : C


20.

class ExceptionClass1 extends Error {
public String toString() {
return "ExceptionClass1";
}
}

class ExceptionClass2 extends Exception {
public String toString() {
return "ExceptionClass2";
}
}

public class ExceptionClassesTest {
private static final int CLASS1 = 10;
private static final int CLASS2 = 20;

public static void main( String[] args ) {
int param = Integer.parseInt(args[0]);
try {
exceptionClassTest( param );
}
catch(Throwable t) {
System.out.println("" + t );
}
}
public static void exceptionClassTest(int param) throws ExceptionClass2 {
try {
if( param == CLASS1 ) throw new ExceptionClass1();
if( param == CLASS2 ) throw new ExceptionClass2();
}
catch( Exception ex ) {
System.out.println("" + ex );
throw (ExceptionClass2)ex;
}
}
}


If you compile the above program and do the following, what is the output ?

1. java ExceptionClassesTest 10
2. java ExceptionClassesTest 20
3. java ExceptionClassesTest 30

a. Cannot do the above because the program will give compilation error
'unreported exception java.lang.ExceptionClass1; must be caught or
declared to be thrown'
b. ExceptionClass1( twice ), ExceptionClass2 ( twice ), No output
c. ExceptionClass1( once ), ExceptionClass2( twice ), No output
d. Cannot do the above because the program will give compilation error
'incompatible types found : ExceptionClass1, required: java.lang.Throwable'

Answer : c


21.

public class ExceptionTest
{
private static final int FIRST_RETURN = 10;
private static final int CATCH_RETURN = 20;
private static final int FINALLY_RETURN = 30;

public static void main( String[] args ) {
int i = 0;
try {
int param = Integer.parseInt( args[0] );
i = raiseException(param);
}
catch(Exception e) { }
System.out.println(i);
}
public static int raiseException(int param) throws Exception {
try {
if( param == FIRST_RETURN ) throw new Exception();
return FIRST_RETURN;
}
catch( Exception e ) {
if( param == CATCH_RETURN ) throw new Exception();
return CATCH_RETURN;
}
finally {
if( param == FINALLY_RETURN ) throw new Exception();
return FINALLY_RETURN;
}
}
}

Assuming that the above has been compiled,
What is the output of the following commands
1. java ExceptionTest 10
2. java ExceptionTest 20
3. java ExceptionTest 30
4. java ExceptionTest 40

a. 20,30,30,30
b. 30,30,30,0
c. 30,30,30,30
d. 30,30,0,30

Answer : d


22.

interface A {
int i = 0;
}


Which of the following is true with respect to the
above code

a. i is static, final and public
b. Invalid declaration
c. i is protected
d. i has package access

Answer : a


23.


class A {
A() { what(); }
void what() { System.out.println( "This is A" ); }
public static void main( String[] args ) {
A a = new A();
}

}

class B extends A {
B() { what(); }
void what() { System.out.println( "This is B" ); }
public static void main( String[] args ) {
new B();
}
}

With respect to the above code, what is the output given by
the following command..

java B

a. This is A, This is B
b. This is B, This is A
c. This is A, This is A
d. This is B, This is B

Answer : d


24.

class A {
int i = 10;
public int what() { return i; }
}
class B extends A {
int i = 17;
public int what() { return i; }
public static void main( String[] args ) {
A a = new B();
System.out.println( a.i );
System.out.println( a.what() );
}
}

With respect to the above code, what is the output of
the following command ?

java B

a. 10, 17
b. 10, 10
c. 17, 17
d. 17, 10

Answer : a


25.

1. class Primitives
2. {
3. public static void main( String[] args )
4. {
5. char c = 90;
6. byte b = 128;
7. int i = 32657;
8. float f = 10.5;
9. System.out.println( " char = " + c );
10. System.out.println( " byte = " + b );
11. System.out.println( " int = " + i );
12. System.out.println( " float = " + f );
13. }
14. }


Which line(s) of the above gives an error on compilation?
a. 5, 6
b. 5, 8
c. 6, 8
d. only 5

Answer : c


26. Assuming c = 4 and d = 14, then which of the following statements is true? 

a. c > 7 && d < 5 || d > 20 
b. c > 0 && d < 5 || d > 50 
c. c > 1 && d < 6 || d > 0 
d. c < 0 && d > 0 || d < 0 


Answer: c 

27.
class E extends Exception { 


class ExceptHandle { 
public static void f() throws E { 

public static void main (String args[]) throws E { 
try { f(); 
System.out.println("no throw"); 

catch (E e) { 
System.out.println(" only handling"); 





Result of this program 

a. Compilation Error 
b. no throw 
c. only handling 
d. no throw only handling 


Answer: b 



28. 

public class A 

public static void main(String[] args) 

System.out.println(new B().g()); 

private int f() 

return 2; 

int g() 

return f(); 



class B extends A { 
public int f() { 
return 1; 





Whats is the out put of the above code 

a. 1 
b. 2 
c. Null 
d. compilation error 


Answer: b 


29. 

class AClass { 
static AClass createA() 

return new AClass(); 
} // createA() 


public class Tester { 
public static void main(String[] parms) { 
AClass aVar = null; 
System.out.println(aVar.createA().hashCode()); 



Compiling and Running of this will result in 

a. Compilation Error 
b. Run time exception (NullPointerException) because aVar is null so can not 
access null object members 
c. No compilation and runtime error. Returns null because aVar is null hence 
static member of this object will also return null 
d. No compilation and runtime error. Returns a value because when accessing 
a static member of an object, object value is not considered 


Answer: d 

30.

1 class XYZ { 
2 int i = 3; 
3 int j = this.i; 
4 static int k = this.i; 
5 static class A 
6 { 
7 static int l; 
8 } 

10 static A anA = new XYZ.A(); 
11 
12 A returnA1() 
13 { 
14 return this.anA; 
15 } 
16 static A returnA2() 
17 { 
18 return this.anA; 
19 } 
20 } 



Compile and Run this code will cause 

a. No Compilation error 
b. Compilation error at line 3 and 14 
c. Compilation error at line 4 and 18 
d. Compilation error at line 5 and 10 


Answer: c 


31.
public class A { 
public static void main(String[] args) { 
float k = 7.0F; 
float m = 1.0F; 
try { 
m = a() * (k = 0.0F); 

catch(Exception e) {} 
System.out.println(k +" - "+m); 

private static float a() throws Exception { 
float m = 23.0F; 
throw new Exception("Its Exception!"); 




The output of the above code is 

a. 7 - 1 
b. 0 - 0 
c. 0 - 23 
d. 7 - 23 


Answer: a 



32.
// File: xyz/A.java 
package xyz; 

public class A { 
protected int protectedVar; 


// File: Test.java 

import xyz.A; 
public class Test { 
private A a = new A() { 
void someMethod() { 
protectedVar = 1; 

}; 



When compile and tried to run above code 

a. Gives compilation error because variable protectedVar can not be accessed from Test class. 
b. Gives compilation error because protectedVar has not been accessed as a.protectedVar 
c. No compilation error because whenever you import a package, all protected/public variables are availble 
d. No compilation error because 'private A a = new A()' creates a subclass of A within Test class.
Answer: D
-------------------------------------------------------------------------------------------
1. Which of the following lines will compile without warning or error. 

A) float f=1.3; 
B) char c="a"; 
C) byte b=257; 
D)int i=10;

Answer: D



2. Which of the following statements are true? 

A) Methods cannot be overriden to be more private
B) Static methods cannot be overloaded
C) Private methods cannot be overloaded
D) An overloaded method cannot throw exceptions not checked in the base class

Answer: A

3. If you wanted to find out where the position of the letter v (ie return 2) in the string s 
containing "Java", which of the following could you use? 

A) mid(2,s); 
B) charAt(2); 
C) s.indexOf('v'); 
D) indexOf(s,'v');

Answer: C

4. Given the following declarations 

String s1=new String("Hello")
String s2=new String("there");
String s3=new String();

Which of the following are legal operations? 

A) s3=s1 + s2; 
B) s3=s1-s2; 
C) s3=s1 & s2; 
D) s3=s1 && s2

Answer: A

5. Which of the following will successfully create an instance of the Vector class and add an element? 
1) Vector v=new Vector(99); 
v[1]=99; 
2) Vector v=new Vector(); 
v.addElement(99); 
3) Vector v=new Vector(); 
v.add(99); 
4 Vector v=new Vector(100); 
v.addElement("99");

Answer: D

6. As per the JDBC Specification for SQL to Java Datatype Mappings, which of the following statements is correct?

a) The SQL datatype DOUBLE maps to the Java datatype float
b) The SQL datatype DOUBLE maps to the Java datatype long
c) The SQL datatype DOUBLE maps to the Java datatype double
d) The SQL datatype DOUBLE maps to the Java datatype int

Answer : c

7.Assuming a method contains code which may raise an Exception (but not a RuntimeException), what is the correct way for a method to indicate that it expects the caller to handle that
exception:

A) throw Exception 
B) throws Exception 
C) new Exception 
D) Don't need to specify anything

Answer: B

8. As per the JDBC Specification for Java to SQL Datatype Mappings, which of the following statements is correct?

a) The Java datatype long maps to the SQL datatype REAL
b) The Java datatype long maps to the SQL datatype DOUBLE
c) The Java datatype long maps to the SQL datatype INTEGER
d) The Java datatype long maps to the SQL datatype BIGINT

Answer : d

9.What class must an inner class extend:

A) The top level class 
B) The Object class 
C) Any class or interface 
D) It must extend an interface

Answer: C

10.What is the effect of adding the sixth element to a vector created in the following manner:

new Vector(5, 10);

A) An IndexOutOfBounds exception is raised. 
B) The vector grows in size to a capacity of 10 elements 
C) The vector grows in size to a capacity of 15 elements 
D) Nothing, the vector will have grown when the fifth element was added

Answer: C



11. What is the value returned by 

“abcd” instanceof Object
A) “abcd”
B) true
C) false
D) String

Answer: B

12. Which of the following are true about constructors?

A) A class inherits its constructors from its parent
B) The compiler supplies a default constructor if no constructors are provided for a class
C) All constructors have a void return type
D) A constructor cannot throw an exception

Answer: B

13. Which of the following are true about an unreachable object?

A) It will be garbage collected
B) Its finalize() method will be invoked
C) It can become reachable again
D) It has a null value

Answer: C

14. Which of the following must be true of the object thrown by a throw statement?

A) It must be assignable to the Throwable type
B) It must be assignable to the Error type
C) It must be assignable to the Exception type
D) It must be assignable to the String type

Answer: A

15. Can a null value e added to a List?

A) Yes
B) Yes, but only if the List is linked
C) Yes, provided that the List is non-empty
D) No

Answer: C

16. Which of the following are valid Java identifiers?

A) %id
B) @id
C) _id
D) #id

Answer: C

17.Which of the following are true about this variable declaration?
private static int I=3; 

A) The value of variable I may not be changed after it is assigned a value
B) Variable I may only be updated by a static method
C) The value of I is shared among all instances of the class in which it is declared
D) Variable I may be accessed within the static methods of other classes

Answer: C


18.

class Aliasing
{
private String s1;
private String s2;

public Aliasing( String a, String b )
{
s1 = a;
s2 = b;
}
public static void main( String[] args )
{
String s1 = new String("Hello");
String s2 = new String("World");
Aliasing a = new Aliasing( s1, s2 );
System.out.println( " Original " + a );
a.swap();
System.out.println( " After swaping " + a );
a.swap2( s1, s2 );
System.out.println( s1 + " " + s2 );
}
public String toString()
{
return s1 + " " + s2;
}
public void swap()
{
String s3 = new String();
s3 = s1;
s1 = s2;
s2 = s3;
}
public static void swap2( String s1, String s2 )
{
String s3 = new String("World");
s1 = s3;
s2 = s1;
s1 = s3;
}
}

If the above program is compiled and executed, what are the values of
s1 and s2 the end of the program ?

a. Hello, World
b. World, Hello
c. World, World
d. Hello, Hello

Answer : A


19.

class A {
A() { System.out.println("A"); }
}

class B {
static A a = new A();
{
System.out.println("C");
}
B() { System.out.println("B"); }
public static void main( String[] args ) {
System.out.println("D");
new B();
}
}

Consider the code given above, what is the output
of the following command

java B

a. A,C,D,B
b. D,A,C,B
c. A,D,C,B
d. No output, the code will give compilation errors

Answer : C


20.

When trying to establish a JDBC connection, it fails with the message
"Class not found". 

This is due to 
a) The DriverManager class is not found
b) The JDBC driver is not registered
c) The JDBC driver does not exist in the CLASSPATH
d) The Connection class is not found

Answer : c

21.

public class ExceptionTest
{
private static final int FIRST_RETURN = 10;
private static final int CATCH_RETURN = 20;
private static final int FINALLY_RETURN = 30;

public static void main( String[] args ) {
int i = 0;
try {
int param = Integer.parseInt( args[0] );
i = raiseException(param);
}
catch(Exception e) { }
System.out.println(i);
}
public static int raiseException(int param) throws Exception {
try {
if( param == FIRST_RETURN ) throw new Exception();
return FIRST_RETURN;
}
catch( Exception e ) {
if( param == CATCH_RETURN ) throw new Exception();
return CATCH_RETURN;
}
finally {
if( param == FINALLY_RETURN ) throw new Exception();
return FINALLY_RETURN;
}
}
}

Assuming that the above has been compiled,
What is the output of the following commands
1. java ExceptionTest 10
2. java ExceptionTest 20
3. java ExceptionTest 30
4. java ExceptionTest 40

a. 20,30,30,30
b. 30,30,30,0
c. 30,30,30,30
d. 30,30,0,30

Answer : d


22.

interface A {
int i = 0;
}


Which of the following is true with respect to the
above code

a. i is static, final and public
b. Invalid declaration
c. i is protected
d. i has package access

Answer : a


23.


class A {
A() { what(); }
void what() { System.out.println( "This is A" ); }
public static void main( String[] args ) {
A a = new A();
}

}

class B extends A {
B() { what(); }
void what() { System.out.println( "This is B" ); }
public static void main( String[] args ) {
new B();
}
}

With respect to the above code, what is the output given by
the following command..

java B

a. This is A, This is B
b. This is B, This is A
c. This is A, This is A
d. This is B, This is B

Answer : d


24.

class A {
int i = 10;
public int what() { return i; }
}
class B extends A {
int i = 17;
public int what() { return i; }
public static void main( String[] args ) {
A a = new B();
System.out.println( a.i );
System.out.println( a.what() );
}
}

With respect to the above code, what is the output of
the following command ?

java B

a. 10, 17
b. 10, 10
c. 17, 17
d. 17, 10

Answer : a


25.

1. class Primitives
2. {
3. public static void main( String[] args )
4. {
5. char c = 90;
6. byte b = 128;
7. int i = 32657;
8. float f = 10.5;
9. System.out.println( " char = " + c );
10. System.out.println( " byte = " + b );
11. System.out.println( " int = " + i );
12. System.out.println( " float = " + f );
13. }
14. }


Which line(s) of the above gives an error on compilation?
a. 5, 6
b. 5, 8
c. 6, 8
d. only 5

Answer : c


26. Assuming c = 4 and d = 14, then which of the following statements is true? 

a. c > 7 && d < 5 || d > 20 
b. c > 0 && d < 5 || d > 50 
c. c > 1 && d < 6 || d > 0 
d. c < 0 && d > 0 || d < 0 


Answe