相关疑难解决方法(0)

Java Static and Dynamic Binding, Overloading

I am practicing for a test and I came across this exercise about overloading and static and dynamic binding. The output of the following code is asked:

class Moe {
    public void print(Moe p) {
        System.out.println("Moe 1");
    }
}

class Larry extends Moe {
    public void print(Moe p) {
        System.out.println("Larry 1");
    }
    public void print(Larry l) {
        System.out.println("Larry 2");
    }
}

class Curly extends Larry {
    public void print(Moe p) {
        System.out.println("Curly 1");
    }
    public void print(Larry l) {
        System.out.println("Curly …
Run Code Online (Sandbox Code Playgroud)

java

2
推荐指数
1
解决办法
676
查看次数

标签 统计

java ×1