Q24
Given:
#1
package handy.dandy;
public class KeyStroke {
public void typeExclamation() {
System.out.println("!");
}
}
#2
package handy; /* Line 1 */
public class Greet { /* Line 2 */
public static void main(String[] args) { /* Line 3 */
String greeting = "Hello"; /* Line 4 */
System.out.print(greeting); /* Line 5 */
KeyStroke stroke = new KeyStroke(); /* Line 6 */
stroke.typeExclamation();
/* Line 7 */
} /* Line 8 */
} /* Line 9 */
What three
modifications, made independently, made to class Greet, enable the code to
compile and run?
A.
Line 6 replaced with handy.dandy.keystroke stroke = new KeyStroke ( );
Line 6 replaced with handy.dandy.keystroke stroke = new KeyStroke ( );
B.
Line 6 replaced with handy.*.KeyStroke = new KeyStroke ( );
Line 6 replaced with handy.*.KeyStroke = new KeyStroke ( );
C.
Line 6 replaced with handy.dandy.KeyStroke stroke = new handy.dandy.KeyStroke();
Line 6 replaced with handy.dandy.KeyStroke stroke = new handy.dandy.KeyStroke();
D.
import handy.*; added before line 1
import handy.*; added before line 1
E.
import handy.dandy.*; added after line 1
import handy.dandy.*; added after line 1
F.
import handy.dandy.KeyStroke; added after line
import handy.dandy.KeyStroke; added after line
G.
import handy.dandy.KeyStroke.typeException(); added before line 1
import handy.dandy.KeyStroke.typeException(); added before line 1
Risposta:
Il codice non compila perchè la classe Greet non riesce a vedere la classe KeyStroke. Funzionano le modifiche :
Il codice non compila perchè la classe Greet non riesce a vedere la classe KeyStroke. Funzionano le modifiche :
C perchè si dichiara tutto il percorso della classe KeyStroke .
E perchè si importa tutto quello che si trova al livello handy.dandy e quindi anche KeyStroke.
F perchè si importa direttamente la classe KeyStroke.
Sono sbagliate:
A perchè si dichiara tutto il percorso della classe KeyStroke solo in un punto del codice mentre va fatto ogni volta che si utilizza KeyStroke.
B perchè ci usa una sintassi sbagliata
G perchè si importa qualcosa al livello sopra KeyStroke che quindi non è importato. Inoltre typeException() proprio non esiste .
Riferimenti : package
Nessun commento:
Posta un commento