It seems pretty simple to me: public access methods can be called freely like you are doing. What part are you confused about? I'm not certain what you mean by "how the compiler checks the access fields".
compiler checks the public,protected,private fields at compile time
Yes, this is part of the answer.
You never call any functions from Rectangle and Triangle. What you do is calling functions of Shape, which gives control to different code parts depending on whatever dynamic dispatch mechanism is used. It does not know which or how many derived classes there is and what bad decisions they made, and does not care: you are working with Shape.