Java - 类“ClassName”之间的区别和公共类“ClassName” [英] Java - The difference between class "ClassName" and public class "ClassName"

查看:205
本文介绍了Java - 类“ClassName”之间的区别和公共类“ClassName”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间有什么区别

  class x {
// code here
}

  public class x {
// code here
}

在因特网上的例子,他们会有 public class 而不是 class ,他们都是简单的程序。我使用 class 作为我的作业。

解决方案

第一个将导致您的类被分配默认可见性,即 package-private (ie:在同一个包内访问)。



第二个使它 public ,即对任何其他类可见。 p>

参考:控制对类成员的访问


What's the difference between

class x {
    //code here
}

and

public class x {
    //code here
}

Sometimes I see examples on the Internet and they'll have public class instead of class and they're all simple programs. I use class for my assignments and so does everybody else

解决方案

The first one will result in your class being assigned the default visibility, that is package-private (ie: accessible within the same package).

The second one makes it public, that is, visible to any other class.

Reference: Controlling Access to Members of a Class

这篇关于Java - 类“ClassName”之间的区别和公共类“ClassName”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆