Thursday, March 29, 2012

How do I prevent classes of the other packages from accessing my members in JAVA?

How do I prevent  classes of the other packages from accessing my members in JAVA?
By using the <package-private> control acces modifier in the members. What is the keyword? None!  Please check out the example:

package ric.interviewqa4java;
public class A{
    int aField;         //visible to classes of the same package
    void aMethod(){}    //the same!
}

No comments:

Post a Comment

Please, before starting to comment, evaluate if what you want to write is useful, respectful and positive. A kid may read this also.

Give a good example!