Java程序展示不同的访问级别

Java程序展示不同的访问级别

Access modifiers are used to set the feature of visibility of some particular classes, interfaces, variables, methods, constructors, data members, and the setter methods in Java programming language.

在Java环境中,我们有不同类型的访问修饰符。

  • 默认 - 如果我们声明一个函数,它只会在特定的包中可见。

  • Private - 如果我们声明一个函数,它只能在特定的类中可见。

  • Protected- 如果我们声明一个函数,它只能在特定的包内或所有子类中可见。

  • 公共 - 如果我们声明一个函数,它将在任何地方可见。

Example

class Study { public void method16() {...} private void method7() {...} } 登录后复制