Error
This static method cannot hide the instance method from ClassName
Error Type
Compile Time
Sample Code
class BuggyBread1{
public String method(){
System.out.println("String Method 1");
return null;
}
}
class BuggyBread1{
public String method(){
System.out.println("String Method 1");
return null;
}
}
class BuggyBread2{
public static String method() {
System.out.println("String Method 2");
return null;
}
}
public static String method() {
System.out.println("String Method 2");
return null;
}
}
Cause
Method Overriding has been broken by declaring the method as static in the derived class. The static method has thus hide the instance method method() of the base class.
Resolution
Either remove the static modifier for method in the derived class
class BuggyBread1{
public String method(){
System.out.println("String Method 1");
return null;
}
}
public String method(){
System.out.println("String Method 1");
return null;
}
}
class BuggyBread2{
public String method() {
System.out.println("String Method 2");
return null;
}
}
public String method() {
System.out.println("String Method 2");
return null;
}
}
or change the name / arguments of the method in derived class so that it shouldn't hide the method definition
class BuggyBread1{
public String method(){
System.out.println("String Method 1");
return null;
}
}
public String method(){
System.out.println("String Method 1");
return null;
}
}
class BuggyBread2{
public static String method(int x) {
System.out.println("String Method 2");
return null;
}
}
public static String method(int x) {
System.out.println("String Method 2");
return null;
}
}