George Gates

Ranch Hand
+ Follow
since Jul 11, 2008
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by George Gates

Hey Ankit,

You have been solving so many doubts on this forum.

I am sure you will carry all their good wishes along with mine.

Good luck and Rock On.


I was solving some random questions for SCJP online.

I can across this code and had no idea what is the output.

Following are the options:
A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.

What is the output of the above code?

In the above line of code, under what condition will if be true and when will it be false?

Please give your opinions.


Hi All,

I have a doubt in reference variable casting.

Assume Dog extends Animal.

1) Is it true that the second statement will compile but not run:

In other words is it safe to believe that, whenever we are down-casting, the program will always compile but never run?


For up-casting is it safe to believe that, it will always compile and run fine.
Are there any special cases where up-casting can cause compilation or run problems?


Badal Chowdhary

I was wondering if there is any file (pdf, doc or html) that contains all the exam watch of the book K&B SCJP 5.

If you know of any, please post the link.


Hi John,

As per the contract, the equals() method must be as least as precise as the hashCode() method is.

In the code above, hashcode() uses 'code' and 'balance' variables. So the equals methods must have both 'code' and 'balance' variables. That is the minimum requirement. Apart from this, you can also add other variables of the class in the equals(). Eg: You can use:
1) code, balance and rate
2) code, balance, rate and name

Once again, the equals method must have atleast code and balance.

Hope this helps.
Hi Hari Haran,
I tried the following code trying to add a list of type 'a'. It did not give me any compiler error.

@ Ashish

Your links dont seem to be working. Please check.

Hari Harann,

Good discovery.

The book (K&B) states that only when you use asList(),any change in one (array or list) also gets updated in the other.

This is however not true for toArray(). This exception is not mentioned in the book though.
Hi Anjali,
The following is your code:

List<? super String>: The use of super indicates that you can add into the collection. But you can only add the type on the right side (in this case String) or any of its subtypes. You can never ever put a supertype in a subtype collection. This is about adding into the collection.

But when it comes to invoking it, you can pass the type on the right side (in this case String) or any of its supertypes (ofcourse including Object).

This is my understanding.
Hi Steve,

I am sorry for the error. I did mean cs.add(o).
Thanks for explaining the solution.
The main concept is you cannot add anything in the collection that has wildcard '?' and extends. In other cases, adding is OK for the same type or any subtypes of the generic type.

Thanks again
Hi All,

This question is from Javabeat 350 mock questions.

Which call(s) to method(addandDisp) are error free?

Options are:
a)only 3
b)only 1 and 3
c)only 1 and 4
d)only 1,2 and 3
e)only 1,3 and 4

Answer: e.

Can some one explain why the answer is 'e' and what is wrong with the other 4 options.

Hi Quirino,

Thanks for answering the questions.

I still have some doubts.

Can you tell how the values of 'i' changes in the 4 iterations?

If arr is a boolean array, how is it possible to say

Shouldn't it be something like this...

Thanks again
Hi All,

I was going through some of the programs. The following two program's output caught me confused.


The answer is:
0 0 3 0.

I could not understand why does it print 3 at the 2nd index.


It does not compile.

But if we replace Boolean by string it complies. Why we cant sort a boolean array?

About quote the source:
I am sorry, I dont remember the exact source. I have been solving from miscellaneous sources on the internet and I put all my doubts in a word file as and when I encounter them. Henceforth, I will take the responsibility of making a note of the source too. (Its unlikely to get the real questions though )


I had previously also posted queries regarding mock tests. I got the following link as a reference

Can someone tell me precisely which mock exams (that are free and available online) map with the objectives of SCJP 5?

I have purchased Javabeat's 350 mock questions. Can someone tell me how much does it map with the SCJP 5 objectives?

I would appreciate if some one could thoroughly guide me as after reading K&B, which mock exams should be practiced before appearing for SCJP 5.0?

Thanks All for your time.

[ August 10, 2008: Message edited by: Badal Chowdhary ]