The permission modifiers in the 1.Java language mainly include private,public, default, Protected, which control access to member variables and member methods of classes and classes .
permission modifiers in the Java language
Syntax formatting when modifying a variable with a permission modifier:
Puclic type attribute 0;
Private type attribute 1;
Private type attribute 2;
Type attribute 3; (default permission modifier generally does not write)
if a member variable of a class is decorated as private, the member variable can only be used in this class and is not visible in subclasses. If it is to be called, it can be obtained through the Get/set method.
Public classBall {//member variables (properties) PrivateString name; Private intweight;//Get/set method when the property is private, it needs to be called in other classes and packages using the Get/set method PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } Public intgetweight () {returnweight; } Public voidSetweight (intweight) { This. Weight =weight; }
Permission modifiers in the Java language