|
NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems
ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en:
http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com. |
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂtulo en concreto puede realizar una donación directa mediante Paypal:
|
Questions
Question 1: What methods would a class that implements thejava.lang.CharSequenceinterface have to implement?
Answer 1:charAt,length,subSequence, andtoString.Question 2: What is wrong with the following interface?
Answer 2: It has a method implementation in it. It should just have a declaration.public interface SomethingIsWrong { void aMethod(int aValue) { System.out.println("Hi Mom"); } }Question 3: Fix the interface in Question 2.
Answer 3:public interface SomethingIsWrong { void aMethod(int aValue); }Question 4: Is the following interface valid?
Answer 4: Yes. Methods are not required. Empty interfaces can be used as types and to mark classes without requiring any particular method implementations. For an example of a useful empty interface, seepublic interface Marker { }java.io.Serializable.Exercises
Exercise 1: Write a class that implements theCharSequenceinterface found in thejava.langpackage. Select one of the sentences from this book to use as the data. Write a smallmainmethod to test your class; make sure to call all four methods.
Answer 1: SeeCharSequenceDemo.javaExercise 2: Suppose that you have written a time server, which periodically notifies its clients of the current date and time. Write an interface that the server could use to enforce a particular protocol on its clients.
Answer 2: SeeTimeClient.java