interface Device
{
public void doIt();
}
public class Electronic implements Device
{
public void doIt()
{
}
}
abstract class Phone1 extends Electronic
{
}
abstract class Phone2 extends Electronic
{
public void doIt(int x)
{
}
}
class Phone3 extends Electronic implements Device
{
public void doStuff()
{
}
}
Can any one tell me why this compiles.. Because “Phone3” implements Device and it should have doIt() method but it does not have. But still this compiles. May i know Y?
implements Deviceis redundant in classPhone3definition. The class in inheriting the fact of implementing theDeviceinterface from theElectronicclass.That is, every class extending
Electronicis implementingDevicealso, and is also inheriting the implementation ofdoItthatElectronicprovides. Every one of them can extend/provide a different implementation ofdoItby overriding it.