Assinging object of inherited class to reference of super class
java
Solution
Look at expression: `x.m(x.at)`. Since `x` is cdeclared as `A`, `x.at` will refer to `at` field in `A`.
However, it gets more complicated when it comes to methods. Although `x` is declared as `A`, `x` in fact is of type `B`, so method `m` will be called from `x`'s acctual class, `B`.
Maybe this coud help.
Problem
Given the follwoing Code: ``` public class A { int at=2; public int m(int i){return at+i;} } class B extends A { int at=3; public int m(int i){return at+5*i;} } public class Main { public static void main(String args[]){ A x = new B(); System.out.println("Output "+x.m(x.at)); } } ``` The output is 13. How does it work? I know that it takes method from B, but what about arguments?