The purpose of the interface is to entrust a specific and well-known contract for a known type of object. For example, by tradition, all stacks have push (), pop (), and peek (). Therefore, by writing an interface, you are directly writing a contract in which everyone who writes the stack should follow.
In other words, this is a template that dictates that any class that calls itself a stack should implement methods called push (), pop (), and peek (), as my example discusses here.
public interface StackInterface { public void push(int x); public int pop(); public void peek(); } public class myStack implements StackInterface{ }
This is an object oriented technique. At this point you will not get compilation because you at least have not implemented methods for interface methods. You will need to write methods that match the interface signatures before you can fully use the interface.
avgvstvs
source share