Permission modifiers in the Java language

Source: Internet
Author: User
Tags modifier modifiers

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.