Manju Kavi

Ranch Hand
+ Follow
since Sep 25, 2008
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 Manju Kavi

Hi,
If we take 2 instances with values you have provided, they are not meaningfully equal, meaning the values of the instance fields of 2 instances (A and B) are not equal. The purpose of overriding hashCode() and equals() methods is to avoid duplicate values and fast searching. So even though equal method returns true and hashCode method doesn't, these are not considered as duplicate values in collection and always hashcode method is called before equals method..
Hi All,
I'm preparing for SCJP exam to take in the month of November and it would be helpful if some certifieds helps me telling how tough exam questions are. So that i can calculate my position on the preperation way.

Thanks,
Manju KT
Hi Venkat,
I meant according to David's question. And according to Qn. 16/7 of K & B Book, even if we declare input as <? extends Object>, but the method takes only <? extends Number>..?
Hi Venkat,
You are wrong because here the return type is <E extends Number>, means anything that extends or subtype of Number!
Hi Vidya,
if this is the correct coding, i agree with Ankith..
public class Test
{
public static void main(String args[]){}
private int num;
public Test(int i)
{
num=i;
}
public int hashCode()
{
int i=(int)(Math.random()*100);
return i*num;
}

}
C is wrong because in generics there is no polymorphism.
We always do something like this

SuperClass s=new SubClass(); //here "s" is polymorphic

But in generics you cant do that

SuperClass<Super> s=new Subclass<Sub>();

not even this works

SuperClass<Super> s=new SuperClass<Sub>();

So in generics, type parameters should always match.
So in case of option C, we are trying to do this
List<Number>=List<Integer>;

List<Number>=List<any Super class of Integer and Integer itself>; // wont work
It should be..
List<Number>= List<Number>;
Or
List<Integer>= List< Integer>;
Hi Lakuma,
Yes options 4 is obviously right. And even i say that the GC informs the object when it is about to be garbage collected. To be more clear GC will call the finalize() method of the object before that object is garbage collected. I think this is what option 3 means "informs your object".
<T extends Class>
It is also used to create a reference of type T, for example
<T extends Object>
then
T t=new Thread();
Yes Nabila is right. But here none of the option is right. Option "A" and "B" are wrong because List is an interface and you cannot call constructor on it. "C" is wrong according to what Nabila said, which is correct.
Nabila,
Rekha is absolutely right, toString() is no where related to casting. Sorry i counldn't reply you before time.
No! until n unless the constructor with new operator is called, nothing is created on heap.
No it will compile.
The Syntax
if(exp);
can be read as if with empty statment. As we know statements end with ";", semicolon alone is an empty statement. You can have something like this also
if(exp);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Yes thats a good question..
when we cannot override a static method then why cant we redeclare it?

But to my knowledge i think its the only way to avoid the subclasses from having the static method with same name as super class (forget overriding as statics are not inherited).