您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes
Introduction
Content
Apply
Reflect
Extend
previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
 
Content Index
Content Page # 6

Indirect inheritance

Indirect inheritance embodies the idea that one thing is a type of another thing, and that thing is in turn a type of something else. For example, if C is a subclass of B , and B is a subclass of A , then C is an indirect subclass of A . Indirect inheritance is handled automatically in Java. 

Such relationships are illustrated in this diagram:

image91.jpg (4833 bytes)

To extend the example above a little, suppose that we define a class called Moveable that describes how to make an object moveable on the screen (in any useful drawing program we would need to be able to move shapes around). But as well as moving Shapes, suppose we have other moveable items (like gridlines or markers on the screen). So a Gridline is a type of Moveable , while a Line and a Circle are types of Shape , which is a type of Moveable . The outline of the Java program that defines these relationships might be: 

class Moveable
{
  // methods that define the class Moveable
}
class Shape extends Moveable
{
  // methods that define the class Shape, that are not
  // included in class Moveable
}
class Circle extends Shape 
{
  // methods that define the class Circle, that are not
  // included in class Moveable or class Shape
}
Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg