Skip to content
CodeKruPro

Static methods are hidden, not overridden

Predict the outputMediumJava onlyAsked in: Capgemini
Main.java
class Parent {
    static String kind() {
        return "Parent static";
    }

    String name() {
        return "Parent instance";
    }
}

class Child extends Parent {
    static String kind() {
        return "Child static";
    }

    @Override
    String name() {
        return "Child instance";
    }
}

public class Main {
    public static void main(String[] args) {
        Parent p = new Child();
        System.out.println(p.kind());
        System.out.println(p.name());
    }
}

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in