gpt4 book ai didi

java - 包之间的继承不存在?

转载 作者:行者123 更新时间:2023-11-29 03:53:18 25 4
gpt4 key购买 nike

请原谅我提出一个愚蠢的问题,但最近我才意识到我一直在做这样的事情

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 javax.swing.*;
import java.awt.*;

public class Calculator extends JFrame implements ItemListener, ActionListener {
...

更具体地说,由于我正在导入 java.awt.*;,我不应该在不执行 import java.awt.event.*;< 的情况下实现监听器吗?/?

最佳答案

Inheritance between packages does not exist?

正确。包只是一个命名空间,它(至少在 Java 中)是不嵌套的。

More specifically, since I'm importing java.awt.*;, shouldn't I be able to implement the listeners without doing import java.awt.event.*;?

你看到的编译错误清楚地反驳了这一点。导入包不会导入其子包。

关于java - 包之间的继承不存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7733496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com