简体   繁体   中英

Why we can't write class Child implements AnyInterface extends Base in Java?

When we are extending an class and implementing an interface we write it as-

public interface AnyInterface{ ---- }

public class Base{  -- }

public class Child extends Base implements AnyInterface{ ---- }

now my question is why cant we write it as -

public class child implements AnyInterface extends Base{ --- }

Because that's not the syntax the language chose.

What you are proposing would only add to the complexity of the language, not to mention reducing its readability. Why have more than on syntax when one works?

We may extend only one class but may implement one to many interfaces. In that case, it would be more reader-friendly to have the extend-ing first before the implement-ing stuff.

because classes are there for individual operation where as the interface are there for multiple operation as we are defining the services in the child classes.so there is no chance for ambiguity .The single responsibility principle states that class should do one thing only. Multiple inheritance is highly correlated with probability of multiple responsibilities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM