This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
We don't, unless we are JDBC driver writers. Interfaces need implementations otherwise you can't use them. The JDBC driver provides implementations of all the JDBC interfaces for whatever database it connects to. When you call createStatement() its the implementation that is returned. Try writing:
I think whoever said "can't create an object of an interface" has misunderstood implementation. You can create an object of an interface, but indirectly, by implementing it. You can create a class which implements that interface, either as an ordinary (concrete) class or an anonymous class. Remember you can do this in several stages in an inheritance hierarchy, some of which stages might be abstract classes or other interfaces.Here the Statement object "hides" an implementation of the ResultSet interface which is what is actually returned. So the statement implements the interface ResultSet and returns an object of that implementation, which is an object of ResultSet. Have a look at my Engine and GrowingPlant examples from three years ago. Read that discussion. Find the lineand change it toChange "Tree" to "GrwoingPlant" in all the for-each loops. See whether you can see any difference in the output.
Ad a few lines to the original classesAdd a new classNow see what happens. Every member of the "trees" array is an instance of the GrowingPlant interface. Create the Lithops class, where the plant grows 1mm taller every time.
Joined: Aug 16, 2010
hii thank s s o much i got the concept..thanks for giving such a nice explenation