Given:
abstract class
Boat {
public static void
main(String[] args) {
}
}
class
Sailboat extends Boat {
public static void
main(String[] args) {
Boat b = new
Sailboat(); // Line A
Boat b2 = new Boat();
// Line B
}
String doFloat() { return "slow
float"; } // Line C
void doDock() { } // Line D
}
Which two are true about the lines labeled A through D?
A.
The code compiles and runs as is.
B.
If only line A is removed, the code will compile and run.
C.
If only line B is removed, the code will compile and run.
D.
If only line D is removed, the code will compile and run.
E.
Line C is optional to allow the code to compile and run.
F.
Line C is mandatory to allow the code to compile and run.
La risposta è CE
Il codice non compila a causa della linea di codice
B :
Boat b2 = new Boat(); // Line B
Infatti si sta cercando di instanziare una classe
astratta ma an abstract class can never
be instantiated per definizione.
Quindi A è sbagliato e anche B e D perché l’errore è
dato dalla linea B che in questi due casi rimane; invece la C è giusta perché rimuovendo la linea B
si ottiene la compilazione del codice.
La linea C non è affatto obbligatoria per far
compilare il codice, e quindi è giusta la E
mentre è sbagliata la F.
Riferimenti :
http://docs.oracle.com/javase/tutorial/information/glossary.html
Nessun commento:
Posta un commento