|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
Do you have paypal account? Click Here to pay now and get the questions.
|
|
SCJP 1.5 Generics Mock Exam Questions - 6
4) Which of the following statements hold true in the following program?
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.");
}
}
1. The program will not compile.
2. The program will compile but will throw run-time exception.
3. The statement 'X' manifests that objects of type Instrument as well as sub-types can be added
to the list 'allInstruments'.
4. It is not possible to add any type of objects to the list 'allInstruments'.
5. The only possible element that can be added to the list 'allInstruments' is 'null'.
Answer
4) 1,5.
The declaration 'allInstruments' manifests a list, whose reference can point to a similar declaration of list holding Instrument objects or sub-class of Instrument objects. It is not possible to add elements into the list 'allInstruments'. The only permissible allowed type is 'null'.
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|