Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

APCS Interface Given the interfaces below answer: (realizes means implements) pu

ID: 3853715 • Letter: A

Question

APCS Interface   

Given the interfaces below answer: (realizes means implements)

public interface Animal                       public interface Canine {                            {

void eat( );                                              void growl( );

void sleep( );                                        }

void run( );

                  }

1) Write the heading for a class called Dog that realizes Animal

_________________________________________________________________________

2) How many methods must the Dog class have in it if it realizes Animal? ________

3) Can a Class called Cat also realize the Animal interface if                                    ________

the Dog class already realizes it? (yes/no)

4) Write the heading for a class called Dog that realizes both Animal and Canine

_________________________________________________________________________

5) How many methods must the Dog class have in it if it                                 ________

realizes Animal and Canine?

6) Can a Class called Cat also realize the Animal and Canine interfaces if ________

the Dog class already realizes both of them? (yes/no)

7) Write (Y)es or (N)o whether the method eat( ) in the Animal interface is the following

a) public   ______                b) private    ______              c) static     ______

d) abstract    ______            e) final        ______

8) Write the statement that will declare an object called fido that has a reference to Animal

and is an object of Dog class.

_________________________________________________________________________

9) PetDog is a class that realizes Canine.

Write the growl method code for the heading and one line body of System.out.println(“Nice doggy”);

10) PetDog is a class that realizes Canine and Wolf is a class that realizes Canine ______

        Given: Animal lassie = new PetDog( ); and Animal bigBadWolf = new Wolf( );

        then lassie.growl( ); and bigBadWolf.growl( ); is an example of

a) polymorphism      b) inheritence           c) magic         d) casting                 

                                   

11) Can the Canine interface be the following? (yes/no) ______

public interface Canine{

void growl( );

final int legs = 4;

}

12) Can the Canine interface be the following? (yes/no) ______

public interface Canine{

private int legs = 4;

void growl( );

           }

13) Can the Canine interface be the following? (yes/no) _

public interface Canine{

void growl( ){

                          System.out.println(“Nice doggy”);

                      }

             }

14) Consider the following interface and class:

     public interface I {

public void m1();

public void m2();

     }

     public class C implements I {

// code for class C

     }

What must be true about the code for class C, in order for it to compile successfully?

15) What's wrong with the code for the following interface? What should be changed to make a

valid interface for objects that have a color?

public interface Colored {

   private Color color;

  

   public Color getColor() {

     return this.color;

}

}

16.) Can a class implement two interfaces that each contains the same method signature? Explain.

17) Create an interface called Visible that includes two methods: makeVisible and makeInvisible. Both methods should take no parameters and should return a boolean result.

Explanation / Answer

1)Answer:

class Dog implements Animal

{

}

2)Answer: it can have zero methods.

explanation : there is no certain restriction for the number of method must have, while impelementing a class

3)answer: yes..

explanation: yes two or more classes can implements the same class, because here Animal acts like template to all the classes which are implementing it

4)answer :

class Dog implements Animal,Canine

{}