*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics Question" Watch "Generics Question" New topic
Author

Generics Question

Nikhil Shah Jain
Ranch Hand

Joined: Apr 21, 2009
Posts: 31


And:


Does this code compile?
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
What happened when you tried to compile it ?


JDBCSupport - An easy to use, light-weight JDBC framework -
Nikhil Shah Jain
Ranch Hand

Joined: Apr 21, 2009
Posts: 31
Alright, the answer in the mock exam is wrong.
The code does not compile.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18756
    
  40

Nikhil L Shah wrote:Alright, the answer in the mock exam is wrong.
The code does not compile.



Why not? What was the compile error?

Henry
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Nikhil L Shah wrote:Alright, the answer in the mock exam is wrong.
The code does not compile.

Really? I just tried it out and did not get any compiler errors.

Please QuoteYourSources when you copy a question from a book, mock exam or other source - tell us where this question is from.
Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 62
    
    1
Nikhil L Shah wrote:Alright, the answer in the mock exam is wrong.
The code does not compile.


Are you sure???
According to me it should compile, nothing invalid in it. I dont have access to jdk now so I cant really try it out now.....

In my dry run:
Code has an implementer(B) of interface(A) which correctly overrides the interface's lone method a().

and then you are adding into an ArrayList of type A something which IS-A A(ie, B)

So, I see no problem in this.
Mario Gimenez
Ranch Hand

Joined: Mar 23, 2010
Posts: 38
For me work fine.
Why do you say that??'
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Nikhil L Shah wrote:Alright, the answer in the mock exam is wrong.
The code does not compile.


The two code snaps will compile!
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Compiles OK here to. I ran this little prog




Everything compiled and ran fine.

Why did you think it would not compile?
 
wood burning stoves
 
subject: Generics Question