Which of these is a consequnce of removing a method declaration from an interface after it has been implemented?a. There are no consequences, interfaces can always be modified to remove methods. b. The method definitions would need to be removed from every subclass that implements the interface.c. Code would breakwhenever an interface reference is used to polymorphicaly call the method in an instance of an implementing class

Respuesta :

Answer:

Option (a)

Explanation:

It will not produce any error as if a function is declared in the interface and then implemented by a class same function can be defined, but if that declaration is removed then also that class will consider that method as new declaration and it won't produce any type of error. For example : if following code of Java  is run -

interface printing{  

   void print_it();   //method declared

   }  

class Student implements printing{  

public void print_it()    //method implemented

{

   System.out.println("Hello World");

}      

public static void main(String args[]){  

Student obj = new Student();  

obj.print_it();    //method called

   }  

}

OUTPUT :

Hello world

But if the program is altered and declaration of print_it is deleted from the interface like following :

interface printing{  

//method is removed from here

   }  

class Student implements printing{  

public void print_it()    //method implemented

{

   System.out.println("Hello World");

}      

public static void main(String args[]){  

Student obj = new Student();  

obj.print_it();    //method called

   }  

}

Still no error is generated and same output is displayed as before.