In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "what is the difference between parameters and parameters in Java", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "what is the difference between parameters and parameters in Java".
Catalogue
About the assignment of variables:
If the variable is a basic data type, the value assigned is the data value saved by the variable.
If the variable is a reference data type, the value assigned is the address value of the data held by the variable.
Public class ValueTransferTest {public static void main (String [] args) {System.out.println ("* basic data type: *"); int m = 10; int n = m System.out.println ("m =" + m + ", n =" + n); n = 20; System.out.println ("m =" + m + ", n =" + n) System.out.println ("* reference data type: *"); Order o1 = new Order (); o1.orderId = 1001; Order O2 = o1 / / after assignment, the address values of o1 and O2 are the same, pointing to the same object entity in the heap space. System.out.println ("o1.orderId =" + o1.orderId + ", o2.orderId =" + o2.orderId); o2.orderId = 1002; System.out.println ("o1.orderId =" + o1.orderId + ", o2.orderId =" + o2.orderId);}} class Order {int orderId }
The transfer mechanism of the formal parameters of the method: value transfer
1. Formal parameters: parameters in declared parentheses when a method is defined
Argument: the data actually passed to the parameter when the method is called
two。 Value transfer mechanism:
If the parameter is a basic data type, what the argument assigns to the parameter is the actual stored data value of the parameter.
If the parameter is a reference data type, the argument is assigned to the parameter is the address value of the argument storage data.
Public class ValueTransferTest1 {public static void main (String [] args) {int m = 10; int n = 20; System.out.println ("m =" + m + ", n =" + n); / / the operation / / int temp = m to exchange the values of two variables / / m = nbank / n = temp; ValueTransferTest1 test = new ValueTransferTest1 (); test.swap (m, n); System.out.println ("m =" + m + ", n =" + n) } public void swap (int m drawing int n) {int temp = m; m = n; n = temp }} public class ValueTransferTest2 {public static void main (String [] args) {Data data = new Data (); data.m = 10; data.n = 20; System.out.println ("m =" + data.m + ", n =" + data.n) / / swap m and n values / / int temp = data.m;// data.m = data.n;// data.n = temp; ValueTransferTest2 test = new ValueTransferTest2 (); test.swap (data) System.out.println ("m =" + data.m + ", n =" + data.n);} public void swap (Data data) {int temp = data.m; data.m = data.n; data.n = temp }} class Data {int m; int n;} the above is the content of this article on "what is the difference between formal parameters and actual parameters in Java". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about related knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.