Fields and properties in Java

Source: Internet
Author: User

Properties in Java are generally understood as get and set methods. A field, usually called a "class member."

A property is limited to the declaration of a method in a class and is not related to other members of the class. For example:
void SetA (String s)
{}
String Geta ()
{}
When you have such a pair of methods in a class, we can say that the class has a read-write a property (note that it is lowercase a). Properties that contain both the get accessor and the set accessor are called Read-write properties (Read-write property). Properties that only have a get accessor are called read-only properties (Read-only property). Properties that only have a set accessor are called write-only properties (Write-only property).


A class Member (field), typically a class member variable defined in a class, for example:
public class A
{
Private String s = "123";
}
We can say that there is a member variable called S in Class A.
1. Fields: class Card{ private string Name;} 2. Properties: The property contains two modules: the set and Get,set modules are responsible for writing the property, and the Get module is responsible for reading the properties. There are a number of other operations that can be done in two modules, such as verifying that the assigned value meets the requirements in set and deciding whether to assign a value.  class Card{private string name;Public string Name{get {return this.name;}set {this.name=value;}}}  

Fields and properties in Java

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.