I am having difficulties understanding why i get errors with the following code and then not in the other case:
SCENARIO 1 (has error)
class App{
public static void main(String[]args) {
ClassA a = new ClassB();
a.print();
}
}
class ClassA {
protected void print() {}
}
class ClassB extends ClassA {
void print(){}
//creates error: Cannot reduce the visibility of the inherited method from ClassA
}
SCENARIO 2 (No errors)
class App{
public static void main(String[]args) {
ClassA a = new ClassB();
a.print();
}
}
class ClassA {
protected void print() {}
}
class ClassB extends ClassA {
protected void print(){}
//no error/ Override method
}
Any help much appreciated.