Suppose Animal is an interface that specifies a single method – speak. Now suppose the Dog class implements the Animal interface. In addition to the speak method, the Dog class also has a method called wagTail. Now consider the following code.
Animal a = new Dog();
a.wagTail();

Respuesta :

Answer:

"This above code gives the compile time error".

Explanation:

Missing information:

  • The question does not include the "what is the output" line.

Detailed Explantion:

  • The above question holds a class dog that implements an interface. But the code "Animal a = new Dog();" wants to make an object of the Animal interface, which is not possible.
  • It is because the interface and the abstract class definition say that no user can create a direct object of the interface or the abstract class.
  • If any user wants to call the interface method to speak in the above scenario, then he needs to make the object of Dog class like "Dog a=new Dog()", then an object can call the method of the interface.
  • So the above code gives the compile-time error.
ACCESS MORE