免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1385 | 回复: 4
打印 上一主题 下一主题

can I write two public class in a java file? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-26 13:23 |只看该作者 |倒序浏览
I found I can't write two public class in a java file,only 1 public class is allowed in a java file,and the name of the public class is the name of the java file.

Is it right?

So,I have a question now:

if a class2 in  java file2 wants to uses a class1(not public) in java file1,how can class2 access  class1?

thanks for any hint

论坛徽章:
0
2 [报告]
发表于 2005-03-26 18:17 |只看该作者

can I write two public class in a java file?

Generally speaking, they need to be in the same package. If class1 you mentioned is a inner class, it'll be more complex.

论坛徽章:
0
3 [报告]
发表于 2005-03-26 19:05 |只看该作者

can I write two public class in a java file?

o,i see,thanks,man

论坛徽章:
0
4 [报告]
发表于 2005-03-26 20:58 |只看该作者

can I write two public class in a java file?

I can't express my ideas in English.
因为公共类是在包中共享的,java调用类应该是基于文件名的,所以一个文件只能是一个public类。

论坛徽章:
0
5 [报告]
发表于 2005-03-26 21:21 |只看该作者

can I write two public class in a java file?

原帖由 "baorongabc" 发表:
I can't express my ideas in English.
因为公共类是在包中共享的,java调用类应该是基于文件名的,所以一个文件只能是一个public类。

其实除了公共类可以在包内被访问,还有默认的,保护的 都是可以被访问的,
而且java调用类是基于编译后.class文件文件名
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP