org
| -- Robot.class
|
| -- ex
|-- Pet.class
|
|-- why
|-- Dog.class
And the following source file:
class MyClass {
Robot r;
Pet p;
Dog d;
}
Which statement(s) must be added for the source file to compile? (Choose all that appl
A. package org;
B. import org.;
C. package org.;
D. package org.ex;
E. import org.ex.*;
F. package org.ex.why;
G. package org.ex.why.Dog;
Resposta: B, E e F
B e E ok, mas, por que é a F e não a G??? Se fosse no netbeans eu importaria da maneira da G.
foo
|
test
|
xcom
|--A.class
|--B.java
And these two files:
package xcom;
public class A { }
package xcom;
public class B extends A { }
Which allows B.java to compile? (Choose all that apply.)
A. Set the current directory to xcom then invoke
javac B.java
B. Set the current directory to xcom then invoke
javac -classpath . B.java
C. Set the current directory to test then invoke
javac -classpath . xcom/B.java
D. Set the current directory to test then invoke
javac -classpath xcom B.java
E. Set the current directory to test then invoke
javac -classpath xcom:. B.java
Resposta: C
Mas ao chamar javac -classpath . xcom/B.java eu nao estaria procurando A.java no diretorio atual (test)???
- Given three files:
package xcom;
public class A {
// insert code here
}
package xcom;
public class B extends A {public void doB() { System.out.println("B.doB"); } }
import xcom.B;
class TestXcom {
public static void main(String[] args) {
B b = new B(); b.doB(); b.go();
}
}
Which, inserted at // insert code here will allow all three files to compile? (Choose all
that apply.)
A. void go() { System.out.println(“a.go”); }
B. public void go() { System.out.println(“a.go”); }
C. private void go() { System.out.println(“a.go”); }
D. protected void go() { System.out.println(“a.go”); }
E. None of these options will allow the code to compile
Resposta: B is correct. The public access modifier is the only one that allows code from outside
a package to access methods in a package - regardless of inheritance.
Mas A e B não estão no mesmo pacote???
Abraços e valeu
João Sávio