In a Java class a member ie a field or a method can have acc

In a Java class, a member (i.e., a field or a method) can have access level modifiers including public, private, protected, and package-private (with no explicit modifier). After consulting a reference, describe the difference between those modifiers in terms of the scope of the member being modified.

Solution

Public Access Modifier: as the name suggested public that mean available and accessible to all, no restriction. So if a field, method is defined public that means any class or any method can use no matter if it’s defined in same package/class.

Protected Access Modifier: this one is protected which means accessible to a group only (in comparison to thing which is accessible to authorised group of people only). So if a field or method is defined protected then that can be used only by method and class where it is defined and classes defined in the same package not to all (defined outside the package)

Private Access Modifier: as the name suggests its private to the owner which is class in java, we can think in similar way like a thing which belongs just to owner and not shared with anyone. So if a field or method is defined private then it can be accessible only in class where it is defined.

 In a Java class, a member (i.e., a field or a method) can have access level modifiers including public, private, protected, and package-private (with no explic

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site