본문 바로가기
Java 배우기

Questions and Exercises: Interfaces

by 노화방지 Anti-aging Hairstyle 2016. 1. 5.
반응형

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 {
        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. Your implementation should return the string backwards. Select one of the sentences from this book to use as the data. Write a small mainmethod 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.


반응형

'Java 배우기' 카테고리의 다른 글

Multiple Inheritance of State, Implementation, and Type  (0) 2016.01.05
Inheritance 상속  (0) 2016.01.05
Summary of Interfaces 인터페이스 요약  (0) 2016.01.05
Default Methods 기본 메소드들  (0) 2016.01.05
Evolving Interfaces  (0) 2016.01.05

댓글