In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the way of data transmission between classes in java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Data transfer between java classes
Although I knew the data transfer between java classes when I first learned java, I may also understand it at that time, but I may have forgotten
As it happens, this is used, and then just to pass one data to the last two classes in succession.
Method, either through the constructor or through the set method.
Constructor function
The code is not easy to demonstrate
1. Class A _ C for the purpose of transferring the data from class A to class C.
2. Now create an instance of class An in B (used as a handle), and then "assign" it in the constructor of B (not initialization). Class A should be used as a parameter in the constructor and write the assignment statement to the first line as far as possible.
3. When class B is to be used in class A, it naturally needs to pass a parameter before it can be constructed. Passing "this" as a parameter at this time is equivalent to assigning an instance of An in class B.
4. Because C is to be used in B, the value is passed from B to C in the same way.
5. When passing a value or assigning a handle, write it to the front as far as possible to ensure that the following statement will not call its value as null.
6. The work is done.
Java class and class pass values to each other
To realize that values are passed between Java classes and classes, first the java file must be under the package folder
Package references;public class A {/ * * @ param args * / public static void main (String [] args) {/ / TODO Auto-generated method stub} public static String getA () {return "getA";}} package references Public class B {/ * * @ param args * / public static void main (String [] args) {/ / TODO Auto-generated method stub references.An a=new references.A (); System.out.println (a.getA ());}}
This is the end of the content of "what is the way to transfer data between classes in java". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.