I have started reading the J2ME specifications and found that the interfaces like RecordEnumiration has methods which returns or does some action. For instance, the numRecords() would give the number of records in the RecordEnumiration.
According to my knowledge methods in an interface has ONLY method signatures and no method bodies, that's why when you implement that you have to give the methods a body in your class. But now in this, there is no need to do that. Could you please explain how this happens. What I want to know is that, how these interfaces return values or do any actions.
Thanks a lot
SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
A method that returns a value of interface type, say RecordEnumeration, can't actually return an object whose runtime type is "RecordEnumeration", because you can't instantiate an interface, of course. It has to return an instance of a class that implements that interface. It doesn't have to be a public class -- it can be an instance of a package-private class, or an instance of an inner class, or anything. All you know is that you've been handed a RecordEnumeration, and you can call all of its methods. You don't know the "real" type of that object, but you don't care.
Look at the java.sql package (JDBC) which consists almost entirely of interfaces. You only ever deal with Connection, ResultSet, and Statement variables, not knowing that the objects you're working with are actually instances of classes named (for example) OracleTCPConnection, MysqlResultSet, or JdbcOdbcStatement.