The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Learning the Java Language
Lesson: Interfaces and Packages

Questions and Exercises: Creating and Using Interfaces

Questions

  1. What methods would a class that implements the java.lang.CharSequence interface have to implement?

  2. What is wrong with the following interface?
    public interface SomethingIsWrong {
        public void aMethod(int aValue){
            System.out.println("Hi Mom");
        }
    }
    

  3. Fix the interface in question 2.

  4. Is the following interface valid?
    public interface Marker {
    }
    

Exercises

  1. Write a class that implements the CharSequence interface found in the java.lang package. Select one of the sentences from this book to use as the data. Write a small main method to test your class; make sure to call all four methods.

  2. Suppose you have written a time server that periodically notifies its clients of the current date and time. Write an interface the server could use to enforce a particular protocol on its clients.

Check your answers. (in the Learning the Java Language trail)


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.