Home  >  Article  >  Java  >  Briefly introduce the difference between Java member variables and properties

Briefly introduce the difference between Java member variables and properties

黄舟
黄舟Original
2017-05-28 09:23:551872browse

The following editor will bring you a brief discussion on the difference between Java members Variables and Attributes (the simplest and most understandable explanation). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

Example 1:

A Student pojo class:

public class Student{

private String name;

private int age;

public String getName(){
 return this.name;
}
public void setName(String name){
  this.name = name;
}

public int getAge(){
 return this.age;
}

public void setAge(int age){
  this.age = age;
}
}

Member variables: name and age

Attribute:

Official definition of attribute:

SUN official definition is that attribute refers to get or set After removing get or set from the method name, and changing the first letter of the remaining part to lowercase, it is the attribute of this class.

In this example: attributes refer to: name and age

You can give another example:

Example 2:

public class student{
  public String getName(){
    return " my name is dark_passion !";
  }
}

Member variable: None

Attribute: name;

The above is the detailed content of Briefly introduce the difference between Java member variables and properties. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn