I have a parent class.
import java.util.HashMap; import java.util.Map; public class Parent { Map<String,String> map = new HashMap<String, String>(); public void process(){ System.out.println("parent"); this.checkFunction(); } protected void checkFunction(){ System.out.println("parentC"); System.out.println(map); } public void init(){ (map).put("parent","b"); } }
Now, as expected, I have a child class.
import java.util.HashMap; import java.util.Map; public class Child extends Parent { Map<String,String> map = new HashMap<String, String>(); public void checkFunction(){ System.out.println(map); System.out.println("ChildC"); } public void process(){ super.process(); System.out.println("Child"); } public void init(){ super.init(); (map).put("child","b"); } }
To check what I want, I have a main class.
public class test { public static void main(String[] args) {
When I call a.process (), I assume that it should call child.process (), which will be in the super.process () callback. So far, so good. In the parent process (), it should call checkFunction ().
Now, according to my understanding, it should call checkFunction () of the Parent class. Why does it call Child checkFunction ()?
My conclusion is similar to this
parent {child=b} ChildC Child {child=b} ChildC
I expect it to be
parent parentC {parent=b} Child {child=b} ChildC