Sheryl Pinto

Greenhorn
+ Follow
since Feb 26, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Sheryl Pinto

Hi Sandhi,

You will get an ArithmeticException if you try to divide by 0 at line 1.
0/2 = 0, no ArithmeticException.

Thanks,
Sheryl.
[ March 13, 2008: Message edited by: Sheryl Pinto ]
From the K&B book, Chpt3 - Overloading made Hard

"In every case, when an exact match isn't found, the JVM uses the method with the smallest argument that is wider than the parameter."

which I guess in this case would be:

static void doSomething ( C x , C y )
Hi Sandhi,

There is only one String object and that is "sample". anObj is just a reference pointing to "sample".

After line 7, both anObj and locObj point to "sample".
After line 9, reference anObj points to null but locObj is still pointing to "sample" and thus "sample" is not eligible for GC.

Also see:
http://faq.javaranch.com/java/ScjpFaq#stringLiteralGC

Sheryl.
Hi Nabila,

Instance variables are inherited but they are not polymorphic. Polymorphic invocations are only for overridden instance methods. Not for variables, not for static methods.
This is explained in K&B, Chapt 2. Polymorphism, last para.

So since HelSte hs is a reference to parent type,
hs.nat will be dub.

this.nat be uk123 since 'this' is hm.

If you say
HarMol hs = new HarMol();
hs.nat will be uk123

Hope this helps,
Sheryl.
Hi Srividhya,

pq2 doesnt have any elements and the output wont make any sense unless you add elements.
Insert the below snippet after the line

PriorityQueue<Integer> pq2=new PriorityQueue<Integer>(10,pqs);



Then you will be able to see the reverse sort results.

Sheryl.