java 修饰符默认,Java中的默认访问修饰符是什么?

本文解释了在未明确指定情况下,方法和实例变量的默认访问权限:在Java中,它们都是包内可见(package-private)。构造函数的默认访问性取决于所在包,同一包内的类可以调用。了解如何在类和成员级别使用公共或包内访问。更多信息请参阅链接。
摘要由CSDN通过智能技术生成

What is the default access modifier for a method or an instance variable if I do not state it explicitly?

For example:

package flight.booking;

public class FlightLog

{

private SpecificFlight flight;

FlightLog(SpecificFlight flight)

{

this.flight = flight;

}

}

Is the access modifier of this constructor protected or package? Can other classes in the same package, which is flight.booking, call this constructor?

解决方案

If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.)

At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning.

Full story you can read here (Which I wrote recently):

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值