Punitha krishna

Greenhorn
+ Follow
since Nov 22, 2000
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Punitha krishna

Thanks It is clear now. I guess I didn't read the question properly.
Which assignments are legal?
Select all valid answers.
a. long test = 012;
b. float f = -412;
c. int other = (int)true;
d. double d = 0x12345678;
e. short s = 10;
The correct answers are a,b,d,e.
I don't understand how b and d are correct.
public class Test {
2. public static void main (String args []) {
3. Employee e = new Employee("Bob", 48);
4. e.calculatePay();
5. System.out.println(e.printDetails());
6. e = null;
7. e = new Employee("Denise", 36);
8. e.calculatePay();
9. System.out.println(e.printDetails());
10. }
11. }
In the above question when is e eligible for the garbage collection [ they are asking for the earliest]
The correct answer was at line 7.
I took JXam mock exam and I got a similar question there also and they had two choices line 6 and line 7. I picked line 7
but the correct answer there was line 6.
I am confused now.
So Is it line 6 or line 7.
Can anyone explain
Thanx
Thanx Bill. Jane thanks for the URL. I just started going through it and it makes sense to me.
I forgot to give me e-mail address. Can you please send it to punitha_reddy@hotmail.com
21 years ago
Archana,
Congrats. I am planning to take the exam in a week. Can you please send your JLS notes.
Thanx
21 years ago
What will be the result of calling the following method with an input of 2
public int adder(int N) {
return 0x100 + N++;
}
1. It will return 258
2. It will return 102
3. It will return 259
4. It will return 103
The correct answer is 1
I really don't know how to convert hexadecimal to decimal and vice versa. Also I don't know the conversion between octal and decimal too.
I can convert the simple ones for example 0x12.
Is there any logic for this?
Please someone help me with this.
Thanx
Jane and Vidya
Thanks for replying. Still I don't understand question 3 about unicode and also question 5 regarding IO.
1.public class AQuestion
{
private int i = j;
private int j = 10;
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}
Answers
1.Compiler error complaining about access restriction of private variables of AQuestion.
2.Compiler error complaining about forward referencing.
3.No error - The output is 0;
4.No error - The output is 10;
The correct answer is 2
2.public class AQuestion
{
private int i = giveMeJ();
private int j = 10;
private int giveMeJ()
{
return j;
}
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}
Answers
1.Compiler error complaining about access restriction of private variables of AQuestion.
2.Compiler error complaining about forward referencing.
3.No Compilation error - The output is 0;
4.No Compilation error - The output is 10;
The correct answer is C
I don't understand why in Q#2 the answer is 3 instead of 2.
3. public class ADirtyOne
{
//char a = '\u000A';
}
An attempt to compile the above class
1. will complete successfully.
2. will compile sucessfully but with a warning message.
3. will not compile - complains on an invalid expression.
The correct answer is 3. Since we have comment out the line
//char a = '\u000A';
I thought the answer is 1.
4.Read this piece of code carefully
if("String".replace('g','G') == "String".replace('g','G'))
System.out.println("Equal");
else
System.out.println("Not Equal");

Answers
1.the code will compile an print "Equal".
2.the code will compile an print "Not Equal".
3.the code will cause a compiler error
The correct answer is 2 but I thought it is 1.
5.import java.io.*;
public class TransientWriter implements Externalizable
{

private transient String s = "Hope I can ever be persistant!";
public void writeExternal(ObjectOutput oOut) throws IOException
{
oOut.writeObject(s);
}

public void readExternal(ObjectInput oIn) throws IOException,
ClassNotFoundException
{
s=(String)oIn.readObject();
}
public String toString()
{
return s;
}
}
class K
{
public static void main(String args[]) throws IOException,
ClassNotFoundException
{
TransientWriter tw = new TransientWriter();
ObjectOutputStream out = new ObjectOutputStream(new
FileOutputStream("tw.out"));
out.writeObject(tw);
ObjectInputStream in = new ObjectInputStream(new
FileInputStream("tw.out"));
TransientWriter tw2 = (TransientWriter) in.readObject();
System.out.println(tw2);
}
}
Attempting to compile and run the above code

1.will cause a compiler error due to the attempt to write a transient object.
2.will cause a runtime exception when an attempt is made to write a transient object.
3.will not cause any runtime error and the transient object is writen to the file named "tw.out".
4.will not cause any runtime error and the transient object is not written to the file named "tw.out". The
program prints a blank line on the screen.
The correct answer is 3 but I thought it was 4.
Can anyone help me with this.
Thanx


Which of the following are legal array declarations. Select all correct answers.
A.int i[5][];
B.int i[][];
C.int []i[];
D.int i[5][5];
E.int[][] a;
Correct answer B,C,E
I don't understand why C is correct
1: public void check()
2: {
3: System.out.println(Math.min(-0.0,+0.0));
4: System.out.println(Math.max(-0.0,+0.0));
5: System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0));
6: }

A) prints -0.0, +0.0 and false.
B) prints -0.0, +0.0 and true.
C) prints 0.0, 0.0 and false.
D) prints 0.0, 0.0 and true.
The correct answer is A.
How come System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0)) is true. I thought it is false because Math.min(-0.0,+0.0) is -0.0 and Math.max(0.0,+0.0)) is 0.0.
Thanx in adv
The following code will give
1: Byte b1 = new Byte("127");
2:
3: if(b1.toString() == b1.toString())
4: System.out.println("True");
5: else
6: System.out.println("False");
A) Compilation error, toString() is not avialable for Byte.
B) Prints "True".
C) Prints "False".
The correct answer is C. I thought it was B because b1.toString() gives the memory address of b1. Can any one help me with this.
Thanx in adv.
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:

public class Test {
public static void main (String args []) {
Employee e = new Employee("Bob", 48);
e.calculatePay();
System.out.println(e.printDetails());
e = null;
e = new Employee("Denise", 36);
e.calculatePay();
System.out.println(e.printDetails());
}
}

A.Line 10
B.Line 11
C.Line 7
D.Line 8
E.Never
Select the most appropriate answer.
The correct answer to this question is C which is line 7 but I thought it was line 6, because when you say e=null it is ready to be garbage collected???

Chandru,
Thanx for replying. I still don't understand what caused the run time error.
The following code defines a simple applet:



It is accessed form the following HTML page:



What is the result of compiling and running this applet:
A. Prints "Hello World".
B. Generates a runtime error.
C. Does nothing.
D. Generates a compile time error.
Select the most appropriate answer.
The correct answer is B
I have couple of questions regarding this question.
1. Can we have a constructor in a applet.
2. I don't understand what made the run time error to be generated.
Can anyone please help me with this.
Thx.
I added UBB Code to make this more readable.
Bill
[This message has been edited by bill bozeman (edited November 22, 2000).]