The getValue() method is overridden in two ways. Which one is correct?

The getValue() method is overridden in two ways. Which one is correct?


I:
public class Test {
  public static void main(String[] args) {
    A a = new A();
    System.out.println(a.getValue());
  }
}

class B {
  public String getValue() {
    return "Any object";
  }
}

class A extends B {
  public Object getValue() {
    return "A string";
  }
}

II:
public class Test {
  public static void main(String[] args) {
    A a = new A();
    System.out.println(a.getValue());
  }
}

class B {
  public Object getValue() {
    return "Any object";
  }
}

class A extends B {
  public String getValue() {
    return "A string";
  }
}


A. I
B. II
C. Both I and II
D. Neither

The correct answer is B


Java

Learn More Multiple Choice Question :