0% found this document useful (0 votes)
9 views15 pages

Java Questions

Java Questions

Uploaded by

Srinivas Chary
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views15 pages

Java Questions

Java Questions

Uploaded by

Srinivas Chary
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Each question is multiple choice with five choices.

You must select the one best answer


from the 5 choices in order to score a correct answer (Please mark the answer of your
choice in BOLD LETTERS).
Some questions include additional information needed to answer them, such as sample
code or variable definitions. This information will be provided in a formatted section just
above the question.
Q1)
Sample Code import [Link].*;

class A extends Frame


implements ActionListener, WindowListener
{
public A()
{
Button button1 = new Button("Click Me");
[Link](this);
add(button1);
show();
}
public actionPerformed(ActionEvent e) {}
void b1() { return; }
}

Referring to the above, what statement should be added to actionPerformed() so that b1()
is invoked for a click on button1?
(a)
(b)
(c)
(d)
(e)

if [Link]().equals("button1")) b1();
if [Link] == ButtonAction) b1();
if ([Link]().equals(button1)) b1();
b1();
if [Link] == button1) b1

Q2)
Each method represents a stage in the life of a java applet EXCEPT which one of the
following?
(a)
(b)
(c)
(d)
(e)

stop()
show()
destroy()
init()
start()

Q3)
Sample Code public double SquareRoot( double value )

throws ArithmeticException
{
if (value >= 0) return [Link]( value );
else throw new ArithmeticException();
}
public double func(int x)
{
double y = (double) x;
try {
y = SquareRoot( y );
}
catch(ArithmeticException e) {
y = 0;
}
finally {
--y;
}
return y;
}

Referring to the above, what value is returned when method func(4) is invoked?
(a)
(b)
(c)
(d)
(e)

-2
-1
0
1
2

Q4)
Sample Code int count = 0;

while (count < 12) {


count++;
}

What code is equivalent to the code above?


(a)
(b)
(c)
(d)
(e)

for(int count<12;count==0; ) { count++; }


for(count<12;count=0;count++) { }
for(int count=0;count<12;count++) { count++; }
for(int count=0;count<12;count++) {}
for(int count;count<12;count=0) { count++; }

Q5)
Widget

Choice A

The widget shown above is similar to which standard [Link] class?


(a)
(b)
(c)
(d)
(e)

List
PullMenu
Select
Choice
Menu

Q6)
Sample Code SecurityManager sm = [Link]();
if(sm != null) {
[Link]("[Link]");
}

When an untrusted application executes the code above, what happens if the
SecurityManager object is set up to deny this resource?
(a)
(b)
(c)
(d)
(e)

The SecurityManager will stop the read when read method calls are invoked.
checkRead() will return false
The SecurityManager will cause the java virtual machine to exit.
The SecurityManager will terminate the thread attempting to read the file.
checkRead() will throw a [Link]

Q7)
Sample Code int count = 0;

for(int i = 0,j = 0; i<4; i++,j++)


count += j;

Referring to the above, what is the value of "count" after execution?


(a)
(b)
(c)
(d)
(e)

0
1
3
4
6

Q8)
Sample Code import [Link].*;

class query {
public static void main(String args[]) {
String str = "Select lname,salary from employee" +
" order by salary desc";
Connection c;
// Insert database initialization code here
Statement s = [Link]();
ResultSet rs = [Link](str);
}
}

Which of the code segments below would initialize the database connection in the above
code?
(a)
c = new
Connection("[Link]:Fred",
"ellen", "password");
(b)
[Link]("[Link]");
c = new Connection("[Link]","Fred");
[Link]( "ellen", "password" );
(c)
[Link]("[Link]");
String url = "jdbc:odbc:Fred";
c = [Link](url, "ellen", "password");
(d)

c = [Link](
"[Link]", "Fred");

(e)

c = [Link](
"[Link]", "Fred");
[Link]( "ellen", "password");

Q9)
Sample Code int i = 0;

double value = 1.2;


String str = new String("1.2");
Boolean flag = true;

Which is a valid use of variable "value" as shown above?


(a)
(b)
(c)
(d)
(e)

value += flag;
if(value) i++;
value = ++i;
if([Link]( str )) [Link](str);
value = str;

Q10)
Sample Code class A {

int getIt(int i) {
return 5 + 4*i;
}

}
class B extends A {
int getIt(int i) {
return 4 + 2*i;
}
}

Referring to the above, if a program instantiates a B object and invokes getIt() with a
parameter of 3, what value is returned?
(a)
(b)
(c)
(d)
(e)

0
10
17
null
The compiler will error because of duplicate method names

Q11)
Which statement expresses a value that CANNOT be modified?
(a)
(b)
(c)
(d)
(e)

public
static
public
static
public

static final int ANSWER_TO_ULTIMATE_QUESTION = 42;


volatile int ANSWER_TO_ULTIMATE_QUESTION = 42;
static native long ANSWER_TO_ULTIMATE_QUESTION = 42L;
int ANSWER_TO_ULTIMATE_QUESTION = 42;
transient int ANSWER_TO_ULTIMATE_QUESTION = 42;

Q12)
Sample Code public interface A {

static final int myCount = 10;


abstract public void method1(int i);
abstract public int method2(float f);

-- New File -class B implements A {

Referring to the above, in order to implement A, what must class B do?


(a)
(b)
(c)
(d)
(e)

Override variable myCount


Declare static versions of method1() and method2()
Be in the same package as A
Be abstract
Include non-abstract versions of method1() and method2()

Q13)
When do you override the finalize() method?
(a)
(b)
(c)
(d)
(e)

When you want to kill a thread


When you must ensure that memory allocated to an object is released
When you instantiate a "final" class
When there is cleanup activity needed before an object is destroyed
When an object is no longer needed

Q14)
Which one of the following declarations is NOT valid?
(a)
(b)
(c)
(d)
(e)

char firstname[][];
int[] counts;
char firstname[] = new char[15];
int[] counts = {2,3,5,7,8,14};
char[] answer[] = {"Yes", "No"};

Q15)
Sample Code class A {

int i = 5;
public static void main(String args[]) {
A h = new A();
[Link]();
}
void doIt() {
i += 1;
}

Referring to the above, which one of the following describes the method main()?
(a)
(b)
(c)
(d)
(e)

It is invoked by the system at start up.


It is doIt()'s parent method.
It is a method other objects must invoke before invoking other methods.
It is the core method of the Applet.
It is an arbitrary method.

Q16)
Sample Code int h = 7;

float f = 3f;
float result = h%f;

Referring to the above, what is the value of "result" after execution?


(a)
(b)
(c)
(d)
(e)

0
1.0
2.0
2.33
7.0

Q17)
Sample Code class A {

private int getIt(int i) {


return i*4;
}

Referring to the above, what classes can access method getIt() in class A?
(a)
(b)
(c)
(d)
(e)

Classes in the same package


Subclasses of A.
Class A
Superclasses of A in the same package
All classes

Q18)
What is Java serialization?
(a)
(b)
(c)
(d)
(e)

The ability to examine the encapsulated data of a class.


Distributed persistence.
Remote method invocation.
Marshaling and unmarshaling of remote objects.
The ability to read and write the state of an object

Q19)
Sample Code long time = [Link]();
Referring to the above, following execution, the value of variable time will be the number
of milliseconds since which one of the following?
(a)
(b)
(c)
(d)
(e)

Midnight
The most recent whole minute
Midnight GMT on January 1, 1988
Midnight GMT on January 1, 1970
The most recent even hour

Q20)
Sample Code

int count=0, i=0;


do {
count += i;
i++;
if(count > 5) break;
} while(i<=4);

Referring to the above, what is the value of "count" after execution?


(a)
(b)
(c)
(d)
(e)

0
1
4
6
10

Q21)
Sample Code class A {

int x = 2, y = 4, z = 7;
int calcW() { return x * y; }
class B {
int w = 9;
public int cvert(int i) { return calcW() * w; }
}

Referring to the above, class B is which one of the following?


(a)
(b)
(c)
(d)
(e)

Improper class definition


Inner class
Nested class declaration
Superclass of A
Subclass of A

Q22)
Sample Code int count=0;

for(int i=0; i<10; i++)


count++;

Referring to the above, what is the value of "count" after execution?


(a)
(b)
(c)
(d)
(e)

0
1
9
10
11

Q23)
Sample Code package mypackage;

class MyException extends [Link]


{
public MyException() { super(); }
public MyException( String s ) { super(s); }
}

Referring to the above, which of the following code segments properly generates an
exception of type "MyException"?
(a)
(b)
(c)
(d)
(e)

catch( MyException e) { }
exception new MyException();
MyException e = new MyException(); return e;
throw new MyException("Error Occurred!");
new Exception( MyException );

Q24)
Sample Code if (check4Biz(storeNum) < 10) {}
Referring to the above, what datatype could be returned by method check4Biz()?
(a)
(b)
(c)
(d)
(e)

int
Boolean
char[]
String
[Link]

Q25)
Sample Code int x=3, y=5, z=2;
if(x <= y) {
x += z;
if(z != x)
y = (x - z)/y;
z++;
}
else if (y == 0) {
y++;
z *= y;
}
else y = 10;

Referring to the above, what are the values of x, y, and z after executing the sample code?
(a)
(b)
(c)
(d)
(e)

x=5, y=0, z=3


x=3, y=10, z=2
x=6, y=0, z=3
x=3, y=6, z=3
x=5, y=5, z=3

Q26)
What type of variable can be changed at runtime but is always the same for all objects of
a given class?
(a)
(b)
(c)
(d)
(e)

Final
Static
Public protected
Char
Int

Q27)
What class creates a listening TCP connection?
(a)
(b)
(c)
(d)
(e)

[Link]
[Link]
[Link]
[Link]
[Link]

Q28)
Sample Code float f = 5f;
float g = 2f;
float h;
h = 3+f/g+2;

Referring to the above, what is the final value of h?


(a)
(b)
(c)
(d)
(e)

2
4.2
6
7
7.5

Q29)
Sample Code class Counter {

int count = 0;
int increment() {
int n = count;
count = n + 1;
return n;
}

Referring to the above, which of the following actions would make increment() threadsafe?
(a)
(b)
(c)
(d)
(e)

Implement the "[Link]" interface


Declare increment() synchronized
Declare increment() as static final
Declare Counter synchronized
Modify increment() to make all other threads unrunnable state until the method is
completed

Q30)
Sample Code class A {

public static void main(String args[]) {


int i = 2;
int x = (i == 2) ? 5 : 10;
int y = (i == 5) ? 3 : 8;
[Link](x);
[Link](y);
}

Referring to the above, what is the output?


(a) 0
8
(b) 10
3
(c) 10
0
(d) 5
8
(e) 10
8
Q31)
Sample Code import [Link].*;

// Insert additional code here


Connection con = [Link](url);
String s = "call proc(?,?,?,?)";
CallableStatement cs = [Link](s);
[Link](1,1);
[Link](2,2);
[Link](3,3);
[Link](4,[Link]);

Referring to the above, which of the following commands executes procedure proc(),
which includes two INSERT SQL statements and one OUT parameter?
(a)
(b)
(c)
(d)
(e)

[Link]()
[Link](cs)
[Link]().execute()
ResultSet = [Link]()
[Link]()

Q32)
Applet MyApplet includes custom class Class2. When the browser loads [Link]
and CANNOT find Class2 locally, the browser will do which one of the following?
(a)
(b)
(c)
(d)

Throw a NoSuchClassError and not load the applet


The browser will reject the entire web page and revert to the previous page
Pop open a window asking permission to load a class from an untrusted source
Throw a NoSuchClassException, alert the user, ignore the missing methods, and
continue
(e) Request the needed class file from the web server
Q33)
Which class CANNOT be directly instantiated?
(a)
(b)
(c)
(d)
(e)

[Link]
[Link]
[Link]
[Link]
[Link]

Q34)
Which one of the following about a "persistent" object is true?
(a)
(b)
(c)
(d)
(e)

It is referenced by a daemon thread.


It is stored in a relational database instead of ram.
It uses connection-oriented TCP packets for communication.
It exists beyond the life of the program that created it.
It cannot be garbage collected

Q35)
Sample Code class Class1 {

public static void main(String args[]) {


int i = 0, total = 0;
while(i<4) {
i++;
if (i > 2) break;
total += i;
}
[Link](total);
}

What is the output of the program above?


(a)
(b)
(c)
(d)
(e)

0
1
2
3
6

Q36)
Sample Code int x = 0, y = 0, z = 0;
x = 1;
x = (-x + y++) * ++z;

Referring to the above, what is the value of "x" after execution?


(a)
(b)
(c)
(d)
(e)

-2
-1
0
1
2

Q37)
Sample Code class B extends A {

int xC, yC, k;


void move(int x) {
xC = x;
}

Referring to the above, to enable class B to be instantiated and executed in a separate


thread, which one of the following must you do?
(a)
(b)
(c)
(d)
(e)

Implement Threadable
Instantiate a new Thread
Subclass ThreadGroup
Make the class public, implement Runnable, and add a main() method
Implement Runnable and add a "public void run()" method

Q38)
Sample Code public abstract class A

extends B, C
implements D, E { /*...*/ }

Referring to the above, what is WRONG with the class declaration?


(a)
(b)
(c)
(d)
(e)

Abstract classes cannot inherit.


Public classes cannot implement interfaces.
Classes can only inherit from other classes in the same package.
Classes can only implement one interface.
Classes can only derive directly from one other class.

(a)

When would you ideally hope to start working with Fair Isaac? What time
restraints, if any, do you have which may affect your ability to work with us if
offered a position?

(b)

Are you ok to relocate to Bangalore? (If Applicable Yes / No)

You might also like