Public Interfaces

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

Could the interfaces contain several definitions of the same constant?

Answer:

No. To ensure consistancy, a constant should be defined only once, in one interface.

Public Interfaces

However, it is OK if two interfaces ask for the same method. A class that implements both interfaces only needs to provide one complete method definition to satisfy both interfaces.

An interface can be made public. In fact, this is usually what is done. When a class or interface is public it must be the only public class or interface in the file that contains it. (These notes have been avoiding public classes so that the "copy paste save and run" method can be used with just one file.)

A public interface can be implemented by any class in any file. Many graphical user interface components implement public interfaces. You must use them to work with the GUI features of Java.

QUESTION 23:

Can an interface be made private?