1Z0-803 · Question #224
Given the following four Java file definitions: // Foo.java package facades; public interface Foo { } // Boo.java package facades; public interface Boo extends Foo { } // Woofy.java package org.domain
The correct answer is E. At line n1, Insert: import facades.*;. The Woofy class, located in the org.domain package, needs to implement interfaces Boo and Foo which are defined in the facades package. To reference these interfaces from a different package, an import statement is required.
Question
Given the following four Java file definitions:
// Foo.java package facades; public interface Foo { } // Boo.java package facades; public interface Boo extends Foo { } // Woofy.java package org.domain // line n1 public class Woofy implements Boo, Foo { } // Test.java package.org; public class Test { public static void main(String[] args) { Foo obj=new Woofy(); Which set modifications enable the code to compile and run?
Options
- AAt line n1, Insert: import facades;
- BAt line n1, Insert: import facades.*;
- CAt line n1, Insert: import facades.*;
- DAt line n1, Insert: import facades.Foo, Boo;
- EAt line n1, Insert: import facades.*;
How the community answered
(52 responses)- A2% (1)
- B8% (4)
- C2% (1)
- D4% (2)
- E85% (44)
Why each option
The `Woofy` class, located in the `org.domain` package, needs to implement interfaces `Boo` and `Foo` which are defined in the `facades` package. To reference these interfaces from a different package, an `import` statement is required.
`import facades;` is syntactically incorrect for importing types in Java; it must specify a class/interface name or use the wildcard `*` for all types within a package.
`import facades.Foo, Boo;` is syntactically incorrect for importing multiple specific types; each type requires its own `import` statement or the wildcard `*` should be used for all types from the package.
Inserting `import facades.*;` at line n1 correctly imports all public classes and interfaces from the `facades` package, making `Boo` and `Foo` visible to the `Woofy` class for implementation and enabling the code to compile.
Concept tested: Java package and import statements
Source: https://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
Topics
Community Discussion
No community discussion yet for this question.