Here is the code I'm having problems with:
The interface:
public interface anInterface {
void printSomething();
}
Class that implements the interface:
public class aClass implements anInterface {
public aClass() {
}
public void printSomethingElse() {
System.out.println("Something else");
}
@Override
public void printSomething() {
System.out.println("Something");
}
}
And the main function:
public static void main(String[] args) {
anInterface object = new aClass();
object.printSomething(); // works fine
object.printSomethingElse(); // error
}
Error: Cannot find symbol. Symbol: method printSomethingElse();
Can anybody tell me why this won't work?
Is it possible in Java, when you have a class that implements some interface, to add methods to that class, even though those methods have not been declared in the interface? Or do I have to declare ALL the methods that I will be using in the interface?
I have also tried it in C# and doesn't work either.
What am I doing wrong?
Thanks!!!