Choose the correct statement about the following code: 1: public interface CanFly { 2: void fly(); 3: } 4: interface HasWings { 5: public abstract Object getWindSpan(); 6: } 7: abstract class Falcon implements CanFly, HasWings { 8: } *1 pointA. It compiles without issue.B. The code will not compile because of line 2.C. The code will not compile because of line 4.D. The code will not compile because of line 5.E. The code will not compile because of lines 2 and 5.F. The code will not compile because the class Falcon doesn’t implement the interface methods.
Question
Choose the correct statement about the following code: 1: public interface CanFly { 2: void fly(); 3: } 4: interface HasWings { 5: public abstract Object getWindSpan(); 6: } 7: abstract class Falcon implements CanFly, HasWings { 8: } *1 pointA. It compiles without issue.B. The code will not compile because of line 2.C. The code will not compile because of line 4.D. The code will not compile because of line 5.E. The code will not compile because of lines 2 and 5.F. The code will not compile because the class Falcon doesn’t implement the interface methods.
Solution
The correct statement is F. The code will not compile because the class Falcon doesn’t implement the interface methods.
In Java, when a class implements an interface, it needs to provide the implementation for all the methods declared in the interface. In the given code, the class Falcon is implementing the interfaces CanFly and HasWings but it is not providing the implementation for the methods fly() and getWindSpan(). Hence, the code will not compile.
Similar Questions
Choose the correct statement about the following code: 1: interface HasExoskeleton { 2: abstract int getNumberOfSections(); 3: } 4: abstract class Insect implements HasExoskeleton { 5: abstract int getNumberOfLegs(); 6: } 7: public class Beetle extends Insect { 8: int getNumberOfLegs() { return 6; } 9: } *1 pointA. It compiles and runs without issue.B. The code will not compile because of line 2.C. The code will not compile because of line 4.D. The code will not compile because of line 7.E. It compiles but throws an exception at runtime.
Choose the correct statement about the following code: 1: public interface Herbivore { 2: int amount = 10; 3: public static void eatGrass(); 4: public int chew() { 5: return 13; 6: } 7: } *1 pointA. It compiles and runs without issue.B. The code will not compile because of line 2.C. The code will not compile because of line 3.D. The code will not compile because of line 4.E. The code will not compile because of lines 2 and 3.F. The code will not compile because of lines 3 and 4.
In Java, you have an interface IFlyable with a method Fly(). You have a class Airplane that implements this interface. Which of the following is the correct way to declare the Fly() method in the Airplane class?a.public void Fly() { /*...*/ }b.protected void Fly() { /*...*/ }c.internal void Fly() { /*...*/ }d.private void Fly() { /*...*/ }
Which of the following statements can be inserted in the blank line so that the code will compile successfully? (Choose all that apply) public interface CanHop {} public class Frog implements CanHop { public static void main(String[] args) {______________ frog = new TurtleFrog(); } } public class BrazilianHornedFrog extends Frog {} public class TurtleFrog extends Frog {} *4 pointsA. FrogB. TurtleFrogC. BrazilianHornedFrogD. CanHopE. ObjectF. Long
What is the result of the following code? 1: public abstract class Bird { 2: private void fly() { System.out.println("Bird is flying"); } 3: public static void main(String[] args) { 4: Bird bird = new Pelican(); 5: bird.fly(); 6: } 7: } 8: class Pelican extends Bird { 9: protected void fly() { System.out.println("Pelican is flying"); } 10: } *1 pointA. Bird is flyingB. Pelican is flyingC. The code will not compile because of line 4.D. The code will not compile because of line 5.E. The code will not compile because of line 9.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.