Edward Seager

Greenhorn
+ Follow
since Jan 02, 2010
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 Edward Seager

Hi all,

First of all I would like to say a big thank you to the users here who took the time to answer my questions. I achieved a 95% pass rate and the help I received on this forum certainly contributed to my grade

As a thank you, I am putting together a series of articles highlighting the trickier elements of the SCJP examination. If you are interested in viewing the first article it is located at http://grepmonster.wordpress.com/2011/01/22/things-every-java-programmer-should-know-part-i/.

Cheers,
Thanks for your responses. But this case shows that == can be used to compare Strings. Is there a case where == does not work for comparing Strings?
e.g.



is isEqual always true, even though we are creating separate equals objects? Is it to do with how the JVM uses the String literal pool?
Hi,

I think I have found an error on page 583. The example overrides equals() by comparing Strings using == rather than the equals() method. Surly this is wrong?
Hi,

Why does the following code not compile (implicit cast from int to short)?


Whereas this works fine



Thanks,
Hi,

I'm struggling to understand exactly how the following code is working, regarding inheritance and instance variables.



I thought this code would not compile because Zebra inherits name from Mammal but then redefines it, i.e. using the keyword String before name again.

However, the code runs and prints "furby bray" because instance variables are not overriden but methods are.

I would be very greatful if someone could clarify why it is OK to redefine inherited instance variables, as you cannot redefine variables in the same class. E.g The following code does not compile.


Also, where does the book mention that instance variables are not overriden in Chapter 2?

Thanks
Yes, that is a good explaination. So a is null but that doesn't matter, as it gets replaced by Animal. However using an instance variable instead of the class name produces warnings which I am seeing in Eclipse, but they don't matter either for the sake of the test.

Thanks. (I'll be back when I've read Chapter 2 :-) )

Raju Champaklal wrote:actually the letter a would be replaced the word Animal here....accessing enums is just like accessing static inner classes



Ah, thanks for the info. I guess I will have to wait until Chapter 8 to fully understand how that works.

Minhaj kaimkhani wrote:
above code is working absolutely fine for me, out put is : woof burble.



Yes I know it compiles and runs, I was interested in why it didn't fail on line 9.
Hi all,

I've just started studying for SCJP having completed chapter 1. I managed to get through the self test apart from question 4 which I thought would not compile due to an error on line 9 Here is the code: -



The reason I thought it would not compile is that line 9 is doing a.Dog and a.Fish instead of Animal.DOG and Animal.FISH. I'm unclear as to what variable a holds as it is uninitialised. I've put the code into eclipse and it gives me warnings on line 9: -


Would someone be able to clarify what is going on here?