I've passed validation of the below task however my Intelij IDE shows me the following error "Ambiguous method call: both 'B.method1()' and 'A.method1()' match". why?
I've some more questions about this task:
- Why I was able to run it if my IDE shows an error? Does it have something to do with some configuration?
- If method1 of class A gets a private modifier, should this method be accessible from an external class? I mean the error is shown because both method1 from class A and class B are visible however one is marked as private since the other as public.
package com.codegym.task.task20.task2023;
/*
Making the right conclusion
*/
public class Solution {
public static void main(String[] s) {
A a = new C();
a.method2();
}
public static class A {
private void method1() {
System.out.println("A class, method1"); // 3
}
public void method2() {
System.out.println("A class, method2"); // 2
method1();
}
}
public static class B extends A {
public void method1() {
super.method2();
System.out.println("B class, method1"); // 4
}
public void method2() {
System.out.println("B class, method2");
}
}
public static class C extends B {
public void method1() {
System.out.println("C class, method1");
}
public void method2() {
System.out.println("C class, method2"); // 1
super.method1();
}
}
}