Java simple object transfer, java object transfer
Package Class. Member;
Public class Main {
Public static void main (String [] args ){
Member me = new Member (); // creates a Member object
MO mo = new MO (); // create a member operation object
Mo.mo (me); // call the input method of the member operation object and pass the member object to the member operation object
System. out. println ("\ n ***** member list ******");
System. out. println ("\ n \ t No. \ t points ");
Mo. member (me); // call the output method in MO to pass the member object to it
System. out. println ("\ n **************");
}
}
Package Class. Member;
Import java. util. collections;
/*
* Member
*/
Public class Member {
Int number; // number
Int integral; // points
}
Package Class. Member;
Import java. util. collections;
/*
* Member operation
*/
Public class MO {
Public void mo (Member me) {// input method to get a Member (Member) object named me (passed in the main method)
Keyboard input = new keyboard (System. in); // create a keyboard input object
System. out. print ("Member No.:"); // enter the number of the member number to the me object
Me. number = input. nextInt ();
System. out. print ("Member points:"); // enter the Member points to the integral of the me object.
Me. integral = input. nextInt ();
}
// In fact, the above input and the following output are bent around here, but they are different in different methods. They are passed through (Member me, then it is called by the main method.
Public void member (Member me) {// The Member number entered in the output and the integral method are followed by a member (Member) object named me (passed in the main method)
System. out. println ("\ t" + me. number + "\ t" + me. integral );
}
}