接口優於抽象類(一)java
1接口能夠繼承多個接口,一個類能夠實現多個接口。
ide
demo:spa
singer.java繼承
public interface Singer {接口
public String work();it
}io
Transaction.javaclass
public interface TransactinAction {im
public String actionMethod();demo
}
SongWriter.java
public interface SongWriter extends Singer,TransactinAction {
public String write();
}
WriterImpl.java
public class WriterImpl implements SongWriter {
@Override
public String work() {
return null;
}
@Override
public String actionMethod() {
return null;
}
@Override
public String write() {
return null;
}
}或者
public class WriterImpl implements TransactinAction,Singer{
@Override
public String work() {
// TODO Auto-generated method stub
return null;
}
@Override
public String actionMethod() {
// TODO Auto-generated method stub
return null;
}
}
抽象類只能被繼承。