Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
123 views
in Interview Questions by
I appared for an interview with on of the IT companies. They asked me "can a class be extended by interface in java? why?". Of course we know that it can not be extended. But I had no justification for why.

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

No, Interface only has declaration. Interface does not have definations. So class can have declaration and definations. If you try to extend class by interface, you will break basic rule. So ultimatly compiler will throw an error.

 

Valid:

import java.rmi.Remote;
 
public interface MyInterface extends Remote{
 
}
 
and
 
import org.openqa.selenium.remote.RemoteWebDriver;
 
public class myClass extends RemoteWebDriver{
 
}
 
invalid:
 
import org.openqa.selenium.remote.RemoteWebDriver;
 
public interface myInterface extends RemoteWebDriver{
 
}

Hope above example helps.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...