1、创建MyTest7

package com.example.jvm.bytecode;

import java.util.Date;

public class MyTest7 {

    public static void main(String[] args) {
        Animal animal = new Animal();
        Animal dog = new Dog();
        animal.test("hello");
        dog.test(new Date());

    }
}

//既有方法的重载,又有Dog子类对方法的重写
class Animal{

    public void test(String str){
        System.out.println("animal test");
    }

    public void test(Date date){
        System.out.println("animal date");
    }
}

class Dog extends Animal{

    @Override
    public void test(String str) {
        System.out.println("dog test");
    }

    @Override
    public void test(Date date) {
        System.out.println("dog date");
    }

}

  输出结果:

animal test
dog date

 

针对于方法调用动态分派的过程,虚拟机会在类的方法区建立一个虚方法表的数据结构(virtual method table, vtable),
针对于invokeinterface指令来说,虚拟机会建立一个叫做接口方法表的数据结构(interface method table, itable)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-09-24
  • 2021-12-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2021-08-08
  • 2021-06-30
  • 2022-12-23
  • 2022-01-14
相关资源
相似解决方案