/*Take a look at the following procedure to see if your answer is consistent with the running answer! */classparent{ Public intx; PublicParent p; PublicParent () {} PublicParent (intx) { This. x=x; P= This; } Public voidf () {System.out.println ("Parent::f ()"); } Public voidg () {System.out.println ("Parent::g ()"); } Public voidh () {System.out.println ("Parent::h ()"); f (); g (); Y (); System.out.println ("Look here:" +x); } Private voidy () {System.out.println ("Parent::y ()"); }};classChildextendsparent{ Public intx; PublicChild () {} PublicChild (intx) { Super(x+5); This. x=x; } Public voidf () {System.out.println ("Child F ()"); } Public voidg () {System.out.println ("Child g ()"); }}; Public classThisdemo { Public Static voidMain (string[] args) {Child ch=NewChild (); CH.H (); System.out.println (); CH=NewChild (5); CH.H (); System.out.println (); Ch.p.h (); }} actually C The idea of ++this is similar to this in Java, that is, in polymorphic situations there are some differences, if the method in the C + + base class does not have a virtual modification, then the overridden method of the derived class is not overwritten and does not contain polymorphic (c+ + Polymorphic types: Forced polymorphic, overloaded polymorphic, type-parameterized polymorphic, including polymorphic (by using virtual)! in Java, however, if the subclass overrides the method of the parent class, then overwrite is generated, like C+ + Use the polymorphism of virtual! C ++ Please click here for sample: here! Output Result:/*parent::h () child F () child g () parent::y () look here:0parent::h () Child F () child g () parent::y () Look here:10// The output is xparent::h in the parent class () child F () child g () parent::y () Look here:10//output is the x in the parent class*/
Analysis of the implied this reference in the Java subclass and the parent class