This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes mock exam 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 "mock exam question" Watch "mock exam question" New topic
Author

mock exam question

pritam kamkar
Greenhorn

Joined: Jul 23, 2008
Posts: 3
hi can anybody please tell me whether this program will compile?



i think it will not compile becuase we can not add anything when we use the extends keyword
please correct me if i am wrong
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Did you try compiling the code? Of course compiler won't let you add anything. By <? extends Instrument> you are saying "I sware not to add anything to this list"

Regards.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Vijitha wrote:
Of course compiler won't let you add anything
That's a common mistake. You can always add "null": allInstruments.add(null) compiles fine.
[ July 28, 2008: Message edited by: Ralph Jaus ]

SCJP 5 (98%) - SCBCD 5 (98%)
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3825

Sorry I forgot about it.you can add "null" there.
[ July 28, 2008: Message edited by: Vijitha Kumara ]
 
wood burning stoves
 
subject: mock exam question