在包外部将一个类文件从包中扩展,是否可能?

huangapple go评论75阅读模式
英文:

is it possible for extending a class file from outside the package to the package

问题

我是Java的初学者。我在将一个类从包外导入到包文件时遇到了问题。

在包外部将一个类文件从包中扩展,是否可能?

在这里,我有一个名为mypack的包,在其中有一个名为abc的类文件。在包外,我有另一个名为pacl的类文件,我想将pacl类从外部导入到abc类(位于包内部)。Java是否支持这样做?我已经在网上搜索过,但没有找到答案。

英文:

i am beginner to java . i am having issue with importing a class to the package file from outside the package

在包外部将一个类文件从包中扩展,是否可能?

here i am having a package named mypack and inside it there is class file named abc. outside the package i have an another class file named pacl and i want to import class from pacl to the abc(which is inside the package). does java support this . i have searched the web and haven't got the answer

答案1

得分: 3

你的 pacl 类位于默认包中,因此无法被导入。如果你想要在其他包中的类中导入它,你需要将它放入一个包中。实际上,如果可能的话,你不应该使用默认包,特别是如果你在各个包中有多个类。

英文:

Your pacl class is in the default package, and therefore can't be imported. You'll need to put it in a package if you want to import it to classes in other packages. In fact, you shouldn't be using the default package if at all possible, specially if you have multiple classes in various packages.

huangapple
  • 本文由 发表于 2020年9月2日 17:49:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/63702977.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定