Java Magazine, Jan/Feb 2018
The Evolving Nature of Java Interfaces Understanding multiple inheritance in Java MICHAEL KÖLLING ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 90 new to java In the occasional New to Java series I try to pick topics that invite a deeper understanding of the conceptual background of a language construct Often novice programmers have a working knowledge of a concept that is they can use it in many situations but they lack a deeper understanding of the underlying principles that would lead to writing better code creating better structures and making better decisions about when to use a given construct Java interfaces are often just such a topic In this article I assume that you have a basic understanding of inheritance Java interfaces are closely related to inheritance as are the extends and implements keywords So I will discuss why Java has two diferent inheritance mechanisms indicated by these keywords how abstract classes fit in and what various tasks interfaces can be used for As is so often the case the story of these features starts with some quite simple and elegant ideas that lead to the definition of concepts in early Java versions and the story gets more complicated as Java advances to tackle more intricate real world problems This challenge led to the introduction of default methods in Java 8 which muddied the waters a bit A Little Background on Inheritance Inheritance is straightforward to understand in principle a class can be specified as an extension of another class In such a case the present class is called a subclass and the class its extending is called the superclass Objects of the subclass have all the properties of both the superclass and the subclass They have all fields defined in either subclass or superclass and also all methods from both So far so good PHOTOGRAPH BY JOHN BLYTHE
You must have JavaScript enabled to view digital editions.