aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Lets add some good scjp 5 questions here Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Lets add some good scjp 5 questions here" Watch "Lets add some good scjp 5 questions here" New topic
Author

Lets add some good scjp 5 questions here

Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

Please add some good scjp 5 questions here


Regards, Abdul Mohsin
Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

How many methods contains the compiled class B?

class A<T> {
T ob;
T getOb() {
return ob;
}
void setOb(T ob) {
this.ob = ob;
}
}
public class B extends A<String> {
String getOb() {
return super.getOb();
}
}
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
What do you mean by contained? There is a load of method inherited from class Object - you include those too?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

just check the compiled class B it will contain 2 methods , just check the second method sig.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
class B extends the class A with parameterized type String, and overrides
the method getOb();

B has two methods, one of them is synthetic bridge method.



Regards,
cmbhatt


cmbhatt
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Quite interesting!





We have overridden the getOb() method of the class A, that class B inherits from A<String>. What complier does is quite different; class A's getOb() type will be Object and class B parameter type is String; To handle with this covariant return compiler adds a bridge method with Object return type in the class B.



The effect of the bridge method is to convert any calls to the inherited versions of getOb() to a call to your version, thus override of the base class method effective.


Regards,
cmbhatt
[ April 27, 2007: Message edited by: Chandra Bhatt ]
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
Hi chandra,
What do you mean by bridge method.Please explain.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Arora,

I hope you would have idea of "covariant return" that is allowed with Java 5.0;

Overriding methods can return the subtype of the return type of the overridden method. Suppose Parent class SpecialNumber named getNumber that returns "Number"



and another class MagicalNumber extends the class SpecialNumber like:



Java 5.0 or so compiler won't complain about this and compile FINE!
But to allow us the advantage of covariant return, compiler has to do one extra work. Ask what? That is the bridge method.

Parent class method returns number and child class method returns Double.
Return type mismatch; for that compiler adds a method with the same
signature and return type inside the child class.





Got it?


Regards,
cmbhatt
[ April 27, 2007: Message edited by: Chandra Bhatt ]
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
Yes chandra thanks for the reply and hey i am not good in generics. Can you help me?
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707

Yes chandra thanks for the reply and hey i am not good in generics. Can you help me?


We have so many Generics expert here! You can post your questions/doubts here,
they we surely help you.

I will also try to help you!

By the way if you have some idea of covariant return type and generics,
the above post is quite cool to explain the things well.(as I think)


Regards,
cmbhatt
Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

Hi Chandra,

Thanks for explaining it to me.

Put some good questions of scjp 5 if you have, I will really appreciate.

Abdul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lets add some good scjp 5 questions here
 
Similar Threads
scjp
Passed SCJP
$$$$$$$ SCJP
SCJP in the UK ??
Passed Scjp 1.4