Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are direct and indirect subclasses?

Tags:

java

I was looking at Android development documentation, and I saw this:

public abstract class Buffer
extends Object

Known Direct Subclasses:
ByteBuffer, CharBuffer, DoubleBuffer, FloatBuffer, IntBuffer, LongBuffer, ShortBuffer

Known Indirect Subclasses:
MappedByteBuffer

Buffer is a abstract class that cannot be instantiated. It inherits (extends) Object.

But I am confused about the direct and indirect subclasses. My best guess would be: Direct extend directly from the superclass. Indirect extends from a superclass that directly extends the class in question.

Many thanks for any suggestions,

like image 388
ant2009 Avatar asked Feb 18 '15 03:02

ant2009


People also ask

What is a direct superclass?

■ The direct superclass is the superclass from which the. subclass explicitly inherits. ■ An indirect superclass is any class above the direct. superclass in the class hierarchy. ■ The Java class hierarchy begins with class Object (in.

How do you define subclasses?

Definition: A subclass is a class that derives from another class. A subclass inherits state and behavior from all of its ancestors. The term superclass refers to a class's direct ancestor as well as all of its ascendant classes.

What are superclasses and subclasses?

Definitions: A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).

What are subclasses used for?

Subclasses are classes that can be derived from a parent class by adding some functionality, such as new object variables or new methods. In terms of automaton theory, a subclass adds new states and new rows to the state transition table.


2 Answers

You are correct. A known direct relationship implies that the class is the immediate ancestor. A known in-direct relationship implies that the class is known to be a sub-class, but it may in fact be many levels below the parent.

like image 79
Elliott Frisch Avatar answered Oct 22 '22 14:10

Elliott Frisch


Given class A:

class B extends A // B is direct subclass of A
class C extends B // C is indirect subclass of A
class D extends C // D is indirect subclass of A

you get the point.


Another way to look at it is using this inheritance chain graph (A is the superclass, the rest inherits):

A->B->C->D

B is a direct subclass of A, the rest are indirect subclass of A.

like image 9
Mercury Avatar answered Oct 22 '22 16:10

Mercury