Look at the code below :
class Marsupial { public static boolean isBiped() { return false; } public void getMarsupialDescription() { System.out.println("Value of this : " + this.getClass().getName() + " , Marsupial walks on two legs: " + isBiped()); } } public class Kangaroo extends Marsupial { public static boolean isBiped() { return true; } public void getKangarooDescription() { System.out.println("Value of this : " + this.getClass().getName() + ", Kangaroo hops on two legs: " + isBiped()); } public static void main(String[] args) { Kangaroo joey = new Kangaroo(); joey.getMarsupialDescription(); // Question here joey.getKangarooDescription(); } } The output is :
Value of this : Kangaroo , Marsupial walks on two legs: false Value of this : Kangaroo, Kangaroo hops on two legs: true Now why in the call of getMarsupialDescription(), it will choose static method of Marsupial and not of Kangaroo especially when this points to Kangaroo ?
thispointer to call it.