Access modifiers in java are used to control the access of other classes to access the class or method.
There are different type of access modifiers used
1.Public-It is the default access modifier it means that your class or method is visible to all other classes and method but in its package.
2.Protected-It can be accessed by any class in its package and by subclass that extends it from another package./
3.Private-It can be accessed in it own class only.
public class Bicycle {
private int cadence;
private int gear;
private int speed;
// add an instance variable for the object ID
private int id;
// add a class variable for the
// number of Bicycle objects instantiated
private static int numberOfBicycles = 0;
...
}
0 Comment(s)