sách gpt4 ăn đã đi

Có sự khác biệt nào giữa cấp độ truy cập mặc định (gói) và cấp độ truy cập công khai đối với các phương thức trong một lớp có cấp độ truy cập (gói) mặc định không?

In lại 作者:搜寻专家 更新时间:2023-10-31 19:50:56 28 4
mua khóa gpt4 giày nike

代码中的相同问题:

class Foo {

int getIntProperty () { ... }

CustomObject getObjectProperty () { ... }

void setIntProperty (int i) { ... }

void setObjectProperty (CustomObject obj) { ... }

//any other methods with default access level
}

sự tương phản

class Foo {

public int getIntProperty () { ... }

public CustomObject getObjectProperty () { ... }

public void setIntProperty (int i) { ... }

public void setObjectProperty (CustomObject obj) { ... }

//any other methods with public access level
}

câu trả lời hay nhất

将 Foo 子类化时会有所不同:

public class Bar extends Foo {

}

然后尝试另一个包:

new Bar().getIntProperty ()

它将在您的示例的第二个(所有方法都是公开的)编译,但不会在第一个(所有方法默认访问)

关于java - 具有默认(包)访问级别的类中方法的默认(包)和公共(public)访问级别之间有什么区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2193224/

28 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress