Movatterモバイル変換


[0]ホーム

URL:


Documentation

The Java™ Tutorials
Interfaces and Inheritance
Interfaces
Defining an Interface
Implementing an Interface
Using an Interface as a Type
Evolving Interfaces
Default Methods
Summary of Interfaces
Questions and Exercises
Inheritance
Multiple Inheritance of State, Implementation, and Type
Overriding and Hiding Methods
Polymorphism
Hiding Fields
Using the Keyword super
Object as a Superclass
Writing Final Classes and Methods
Abstract Methods and Classes
Summary of Inheritance
Questions and Exercises
Trail: Learning the Java Language
Lesson: Interfaces and Inheritance
Home Page >Learning the Java Language >Interfaces and Inheritance
« Previous • Trail • Next »

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
SeeDev.java for updated tutorials taking advantage of the latest releases.
SeeJava Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
SeeJDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.

Questions and Exercises: Interfaces

Questions

  1. What methods would a class that implements thejava.lang.CharSequence interface have to implement?
  2. What is wrong with the following interface?
    public interface SomethingIsWrong {    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 theCharSequence interface found in thejava.lang package. Your implementation should return the string backwards. Select one of the sentences from this book to use as the data. Write a smallmain 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.

« PreviousTrailNext »

About Oracle |Contact Us |Legal Notices |Terms of Use |Your Privacy Rights

Copyright © 1995, 2024 Oracle and/or its affiliates. All rights reserved.

Previous page: Summary of Interfaces
Next page: Inheritance

[8]ページ先頭

©2009-2025 Movatter.jp