5 Hiding methods Flashcards

1
Q

When does a static hidden method run?

A

When there is the same static method in the parent and the child, the methods are hidden. When the methods are hidden, the parent version of the static method always runs when it’s a subclassed object (Animal a = new Dog();.

class Test {
    public static void main(String[] args) {
        Foo f = new Bar();
        f.instanceMethod();
        f.classMethod(); //  runs the class method from parent class
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can a static method be overridden?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly