This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in a question of Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in a question of Generics " Watch "Doubt in a question of Generics " New topic
Author

Doubt in a question of Generics

Bijendra S. Rajput
Ranch Hand

Joined: Sep 19, 2006
Posts: 41
Hi,

I took this question from javabeat site.

Question:-
Which ones of the following lines can be compiled without an error?

a)Basket b = new Basket();

b)Basket b1 = new Basket<Fruit>();

c)Basket<Fruit> b2 = new Basket<Fruit>();

d)Basket<Apple> b3 = new Basket<Fruit>();

e)Basket<Fruit> b4 = new Basket<Apple>();

f)Basket<?> b5 = new Basket<Apple>();

g)Basket<Apple> b6 = new Basket<?>();

Ans. a, b, c, f

But according to me, the answer should be a,c and f.
I did not get why ans b is also correct.
Can anyone through a light on it.


Thanks <br /> <br />Regards,<br />------------------------------<br />Bijendra S. Rajput<br />SCJP 1.5<br />------------------------------
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Remember that generics are implemented through type erasure, so Basket<Fruit> is a Basket. When you use a raw type though you lose the type checking at compile-time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in a question of Generics
 
Similar Threads
Generics question1
method types in Generics
Generics doubt.
generics question from javabeat
javabeat mock test