My opinion of the Java function parameter

xiaoxiao2021-03-06  40

In some groups, someone always asked what the Java function passed, this time has time, thinking about it, find a demonstration applet and draw a picture according to his own understanding, if someone palains about my blog, You can discuss Class Obj {string str = "init value"; public string toString () // Overiding rewrites the toString () method, can be explicitly or implicitly call {Return Str " Haha-yang";}}

Public class objref {obj aobj = new obj (); int ain = 11; public void changeoBJ (Obj INOBJ) {INOBJ.STR = "Changed Value"; / / You can change the attribute value of the passing object} public void changepri (int ININT) {ININT = 22;} public static void main (string [] args) {objref oref = new objref (); system.out.println ("1 Before call changeoBJ () Method:" oref.aobj); / / Here, OREF.AOBJ automatically calls the OBJ class toString () method (implicit call) System.out.println ("2 Before Call ChangeObj () Method:" OREF.AOBJ.TOSTRING ()); // Here, oref.aobj calls the OBJ class toString () method (Explicit call) System.Out.println ("3 Before Call ChangeObj () Method:" OREF.AOBJ.STR); OREF.CHANGEOBJ (OREF. AOBJ); System.out.Println ("4After Call ChangeObj () Method:" OREF.AOBJ); // OREF.AOBJ Implicitly invokes the parent class's TSTRING () method system.out.println ("4b after Call changeObj () Method: " Oref.aobj.tostring ()); // OREF.AOBJ Explicitly call the parent class toString () method system.out.println (" 3b Before call changeoBJ () M Ethod: " oref.aobj.str); system.out.println (" =================================== ===== "); system.out.println (" 5 Before call changepri () method: " oref.aint); Oref.changepri (Oref.Aint); System.out.Println (" 6After Call Changepri) () Method: " oref.Aint);

转载请注明原文地址:https://www.9cbs.com/read-56820.html

New Post(0)