How does instance variable invocation work when you do A thing = new B(); where B is a subclass of A?

前端 未结 6 748
予麋鹿
予麋鹿 2021-01-27 17:54

This is probably answered somewhere, but I have no idea what to search for. Imagine you have the following...

The superclass, Animal.java

public class An         


        
6条回答
  •  北海茫月
    2021-01-27 18:32

    All non-static methods in java are by default "virtual functions". Unless they're marked as final (which makes the method not overridable). Java uses a virtual method table to call the correct object's method.

提交回复
热议问题