File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 3817

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: 3817

Sorry I forgot about it.you can add "null" there.
[ July 28, 2008: Message edited by: Vijitha Kumara ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mock exam question
 
Similar Threads
list interface
Generic Problem
Regarding Generics !
Generics Prob
Generics for Interface