Previously seen in Java often a bunch of corresponding set and get, simply know that the set is the value of a pass-through get.
For example:
Books.java
1 PackageTest.testxml;2 3 Public classBooks {4 Private intID;5 PrivateString name;6 Private DoublePrice ;7 PrivateString author;8 9 Ten Public intgetId () { One returnID; A } - Public voidSetId (intID) { - This. ID =ID; the } - PublicString GetName () { - returnname; - } + Public voidsetName (String name) { - This. Name =name; + } A Public DoubleGetPrice () { at returnPrice ; - } - Public voidSetprice (DoublePrice ) { - This. Price =Price ; - } - PublicString Getauthor () { in returnauthor; - } to Public voidSetauthor (String author) { + This. Author =author; - } the}
A books class has several private member variables (private member variables can only be accessed with their own methods in the same class)
So how do the methods in other classes want to access it? This time is accessed through the set and get methods.
Example:
Test01.java
Public class test01 { publicstaticvoid main (string[] args) { books b= New Books (); B.setauthor ("Jiarui"); System.out.println (B.getauthor ()); }
The content of the output is the content "Jiarui" that is set in.
Understanding and use of get and set methods in Java