Inheritance between packages does not exist?
Pardon me for a stupid question but It recently dawned on me that I've been doing things like this
import java.awt.*; import java.awt.event.*; ^ |
for quite some time and I've been thinking "is this really necessary?"
The code below won't compile. My question is why?
import开发者_Go百科 javax.swing.*;
import java.awt.*;
public class Calculator extends JFrame implements ItemListener, ActionListener {
...
More specifically, since I'm importing java.awt.*;
, shouldn't I be able to implement the listeners without doing import java.awt.event.*;
?
Inheritance between packages does not exist?
Correct. A package is just a namespace, which (in Java, at least) are not nested.
More specifically, since I'm importing
java.awt.*;
, shouldn't I be able to implement the listeners without doing importjava.awt.event.*;
?
The compile error you see clearly refutes this. Importing a package does not import its subpackages.
精彩评论