In addition to the static method and the final method in Java (the private method belongs to the final method), all other methods are dynamic bound and run-time bound.
Public classtest{Private voidf () {System.out.println ("Private F ()"); } Public Static voidMain (string[] args) {Test T=NewDerived (); T.F (); }}classDerivedextendstest{ Public voidf () {System.out.println ("Public f ()"); }}/*private F () Private method is automatically considered the final method, there is no polymorphic, static binding, the method of calling the base class directly*/
Only normal method calls can be polymorphic, and if you access a domain directly, the access will be parsed at compile time, with no polymorphic
classsuper{ Public intfield = 0; Public intGetField () {returnfield;}}classSubextendssuper{ Public intField =1; Public intGetField () {returnfield;} Public intGetsuperfield () {return Super. field;}} Public classtest{ Public Static voidMain (string[] args) {Super sup=NewSub (); System.out.println (Sup.field+" "+Sup.getfield ()); Sub Sub=NewSub (); System.out.println (Sub.field+ "" "+sub.getfield () +" "+Sub.getsuperfield ()); }}/*0 1 0*/
If a method is static, its behavior is not polymorphic.
classsuper{ Public Static voidGetField () {System.out.println ("Super"));}}classSubextendssuper{ Public Static voidGetField () {System.out.println ("sub");}} Public classtest{ Public Static voidMain (string[] args) {Super sup=NewSub (); Sup.getfield (); }}/*Super*/
Java Programming Ideas-polymorphic