This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am a newcomer in JavaWorld, but I thought I understood from a book (Head First Java) that interfaces, if not implemented, cannot be instantiated. But I am afraid my understanding was wrong, since, for example, a servlet container can create a ServletRequest object, and ServletRequest is not a class but an interface. How can a ServletRequest be instantiated? Since none of its methods are implemented, how can it do anything?
Hi Francois, Welcome to JavaRanch! You were right the first time. Interfaces cannot be instantiated. A servlet container doesn't create ServletRequest objects -- it creates an instance of some class like org.apache.catalina.HttpServletRequestImpl that implements that interface. Part of writing a servlet container (or a JDBC driver, or any other API that involves interfaces) is providing implementations for all those interfaces. Get it? [ October 15, 2003: Message edited by: Ernest Friedman-Hill ]