英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论