public class KeyStroke {
public void typeExclamation() {
System.out.println("!");
}
}
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 1
import handy.dandy.KeyStroke; added after line 1
G.
import handy.dandy.KeyStroke.typeException(); added before line 1
import handy.dandy.KeyStroke.typeException(); added before line 1
Risposta :C E F
Risposta C,D,F
RispondiEliminaPackage declaration is missing.
RispondiEliminaAccording to exam KeyStroke class is in [handy.dandy] package and Greet class is in [handy] package.
So answer D is fail because import statement like (import package.*) is not full recursive, it means that by importing handy.* you only get access to all handy's classes but not handy.dandy's classes. so to get access to KeyStroke class (inside package handy.dandy) from Greet class
you need to import handy.dandy package (import handy.dandy.*)
All you need to see it is to compile both classes, you'll notice correct answer is (E) not (D).