Hello everyone,
Looking for someone who will be so kind as too possible give me their interpretation of what an interface is good for.
I need to implement one in my assignment and no matter what I read, video's I watch, etc. I am still confused on what the are actually good for.
I am just practicing with it before implementing it in my assignment so this is what I have,
package interfacesamplecode; public class InterfaceSampleCode implements highScores { @Override public void allScores(String name, int score) { System.out.println(highScores.name); System.out.println(highScores.score); } public static void main(String[] args) { InterfaceSampleCode newHighScore = new InterfaceSampleCode(); newHighScore.allScores(name, score); } }
run:
John
150
BUILD SUCCESSFUL (total time: 0 seconds)
To me it seems like you can get the same results if you have the String variables in just another class and you call that class, or even extend that class. You should be able to get the same results, this is were I am having trouble understanding what an interface would actually be good for.
If you can, could you give some real world examples on how they could improve a Java program.
Not looking for any code, just why one would use them.
Thanks,