017-004-008

Extending and Implementing Multiple Interfaces

Hard

Problem Description

Extending and Implementing Multiple Interfaces

In this problem, you will create a program that defines Readable and Writable interfaces, builds a ReadWritable interface extending both, implements it with a TextFile class, and displays the results of read and write operations to standard output.

Learning Objective: Understand the pattern where one interface extends multiple interfaces

Overview

Define Readable and Writable interfaces, then ReadWritable extends both. TextFile implements ReadWritable.

Specifications

  1. Declare String read() in Readable
  2. Declare void write(String data) in Writable
  3. ReadWritable extends both Readable and Writable
  4. TextFile implements ReadWritable:
    • constructor accepts initial content
    • read() returns stored content
    • write(String data) overwrites content
  5. In main, create TextFile and call read, write, read in order

Output Format

Read: Hello
Read: World

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up