Results 1 to 1 of 1
Thread: Generics SCJP
- 01-07-2011, 12:38 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
Generics SCJP
Given this code:
Please explain this affirmation:Java Code:package generics; import java.util.ArrayList; import java.util.List; public class Ques04 { public static void main(String[] args) { List<? extends Instrument> allInstruments = new ArrayList<Instrument>(); // -->X allInstruments.add(new Guitar()); allInstruments.add(new Violin()); } } interface Instrument { public void play(); } class Guitar implements Instrument { public void play(){ System.out.println("Playing Guitar."); } } class Violin implements Instrument { public void play(){ System.out.println("Playing Violin."); } }
The only possible element that can be added to the list 'allInstruments' is 'null'.
Source: SCJP 1.5,SCJP 5.0 Generics Mock Exam Questions - 5
Similar Threads
-
Help with generics
By shai in forum New To JavaReplies: 0Last Post: 08-12-2010, 07:07 AM -
generics
By tascoa in forum Forum LobbyReplies: 2Last Post: 10-09-2008, 07:58 PM -
Help w/ generics
By Hollywood in forum New To JavaReplies: 2Last Post: 02-16-2008, 03:08 AM -
Generics
By sireesha in forum New To JavaReplies: 2Last Post: 01-10-2008, 11:08 PM -
Generics
By eva in forum New To JavaReplies: 2Last Post: 01-04-2008, 09:10 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks