I am new to Java and I was wondering how I would go about doing something like this.
Interface file:
public interface ExampleInterface {
void doSomething();
}
Implementation file (in same directory):
public class ExampleImplementation implements ExampleInterface {
void doSomething() {
// code goes here
}
}
EDIT: Hehe, nobody noticed that I forgot to add the class keyword.
Everything looks good in your example.
Remeber that java has packages and in above example you don't precise package so interface and class are in default package. You must put this files in some directory and then compile class file.
To compile use:
javac ExampleImplementation.java
Or better, use some IDE (Eclipse or Netbeans) then if something will be wrong IDE will be notify you and tell what error you encountered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With