Description of issue:
When trying to run methods in a subclass that implements an interface, the compile will error out with the error
Main.java:5: error: cannot find symbol
This occurs regardless of package locations, code location (ie: all code in one file vs. split out into separate *.java files), or methods implemented.
Example of the issue:
I have 2 classes and an interface, A, B, and myInterface. Class A is abstract while B inherits from A and implements myInterface. The problem is, when I run my code, I cannot call any methods from the interface I implemented.
interface myInterface {
public void printSomething();
}
abstract class A {
int aVal;
A() {
this.aVal = 0;
}
public int getVal() {
return aVal;
}
}
class B extends A implements myInterface {
B() {
super();
}
}
public void printSomething() {
System.out.println("Something");
}
class Main {
public static void main(String[] args) {
A bObj = new B();
bObj.printSomething();
// Throws
// Main.java:5: error: cannot find symbol
// bObj.printSomething();
// ^
// symbol: method printSomething()
// location: variable bObj of type A
// 1 error
}
}
For easier running and viewing, I have the same code as above saved here as well.
https://repl.it/repls/IdealMobileUserinterface
Why is this happening, and how would I go about resolving the issue? I've stumped myself and my teacher trying to figure this one out.
myObjas eitherBormyInterface,Adoesn't have the method.