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)
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!
浙公网安备 33010602011771号