"Is-a" or "inheritance" (sometimes also called "generalization") relationships capture a hierarchal relationship between classes of objects. For instance, a "fruit" is a generalization of "apple", "orange", "mango" and many others. We say that fruit is an abstraction of apple, orange, etc. Conversely, we can say that since apples are fruit (i.e. an apple "is-a" fruit), that they inherit all the properties common to all fruit, such as being a fleshy container for the seed of a plant.
| UML Class Diagram Showing Inheritance |
|---|
![]() |
UML Syntax:
UML Syntax:
In Java, inheritance relationships are declared using the extends keyword when declaring a class. A subclass "extends" a superclass, which means that the subclass is a concrete example of the more abstract superclass. For instance, the class Apple would extend the class Fruit.
public class Apple extends Fruit {
...
}Extend really models what an object intrinsically is--its true "being" as it were. This is particularly useful when the superclass has particular concrete behaviors that all the subclasses should exhibit. However, "is-a" can really be more of an "acts-like-a" relationship. This stems from the perspective that all objects are defined soley by their behaviors. We can never truly know what an object truly is, only how it acts. If two objects behave identically (at some abstract level) then we say that they are abstractly equivalent. What we need is a way to express the pure behavioral aspects of an object. Java has a the keyword implements which is used to show generalization of a pure behavioral abstraction called an interface. An interface has a similar syntax to a class, but only specifies behaviors in terms of the "signatures" (the input and output types) of the methods. For example we could have
public interface ISteerable {
public abstract void turnLeft();
public abstract void turnRight();
}
public class Truck implements ISteerable {
public void turnLeft() {
// turn the tires to the left
}
public void turnRight() {
// turn the tires to the right
}
}
public class Boat implements ISteerable {
public void turnLeft() {
// turn the rudder to the left
}
public void turnRight() {
// turn the rudder to the right
}
}
Java keywords public, abstract and void:
public class, method or field can be seen and used by anyone. Contrasts with private (seen and used only by that class) and package (seen and used only by classes in the same package). We'll talk more about these later.
An abstract class or method is a purely abstract definition in that it specifies the existence of a behavior without specifying exactly what that behavior is.
A void return type declares a non-existent return value, that is, no return value at all.
| UML Class Diagram Showing Implementation |
|---|
![]() |







Objects and Classes




"Accessible versions of this collection are available at Bookshare. DAISY and BRF provided."