The Class Hierarchy for JFrame and Frame

For review, let's cover the class hierarchy of JFrame and then Frame. Start up the interactive interpreter and follow along. To get the superclass of JFrame, import JFrame, and then inspect its superclass property.

>>> from javax.swing import JFrame

>>> JFrame.superclass

<jclass java.awt.Frame at 214168159>

To find out Frame's superclass, append anotliee superclass to it. S ince superclass is au instance of j class and j class lias the proporty superclass, we can get the superclass of JFrame's superclass like this:

>>> JFrame.superclass.superclass <jclass java.awt.Window at 217313887>

We can continue to do this until we hit Object.

>>> JFrame.superclass.superclass.superclass <jclass java.awt.Container at 219411039>

>>> JFrame.superclass.superclass.superclass.superclass <jclass java.awt.Component at 221770335>

>>> JFrame.superclass.superclass.superclass.superclass.superclass <j class j ava.lang.Object at -1247546800>

Unlike Python classes, Java prograbllbing language classes can only singly inherit from a superclass, so they have a narrow chain of superclasses. JFrame's class hierarchy looks like this:

Object "—^Component —"^Container "^Window —^Frame —^ JFrame

Frame's class hierarchy looks like this:

Ob j ect "—^Component Container Window —^ Frame

What's revealed is that JFrame and Frame inherit functionality from Container,Component, and Window. To find out more about these base classes and how they relate to JFrame and Frame, look them up in the Java API documentation.

Was this article helpful?

0 0

Post a comment