Java关键字之前的Java中的public关键字? [英] public keyword in Java before class keyword?

查看:182
本文介绍了Java关键字之前的Java中的public关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我看到过人们使用public class class关键字的代码,这是什么意思?

是否只使用了class关键字?

下面提到的一段这样的代码。



In Java I have seen code where people use public before class keyword,what does that mean?
Is it same like if class keyword is only used?
one such piece of code mentioned below.

public class CableModem extends Modem 
{
 String method = "cable connection";

public void connect() 
{
 System.out.println("Connecting to the Internet ...");
 System.out.println("Using a " + method);
}
 

}

推荐答案

http://www.tutorialspoint.com/java/java_access_modifiers.htm [ ^ ]


public 关键字是一个访问说明符,允许控制类成员的可见性。当一个类成员被声明为public时,那个成员可以被声明它的类 outside 访问。 (与公众相反的是私人,这可以防止成员被其类之外定义的代码使用。)



简而言之:

公开 - 表示班级(程序)可供任何其他班级使用。
The public keyword is an access specifier, which allows to control the visibility of class members. When a class member is declared as public, then that member may be accessed by code outside the class in which it is declared. (The opposite of public is private, which prevents a member from being used by code defined outside of its class.)

In-short:
Public - means the class (program) is available for use by any other class.


这篇关于Java关键字之前的Java中的public关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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