Write two interfaces, one called FriendFinder and one called MediaPoster. You must thenwrite a Java class that implements both of these interfaces, called MySocial. Classes adheringto the FriendFinder interface must implement a void notifyFriendRequest () methodThose classes adhering to the MediaPoster interface must implement a numMediaTypes ()method, which returns the maximum number of media types that people can post. By default inthe MediaPoster interface, the numMediaTypes method returns the integer value 1.
时间: 2024-03-25 12:35:30 浏览: 83
Here's an example implementation in Java:
```java
// FriendFinder interface
interface FriendFinder {
void notifyFriendRequest();
}
// MediaPoster interface
interface MediaPoster {
default int numMediaTypes() {
return 1;
}
}
// MySocial class implements both interfaces
class MySocial implements FriendFinder, MediaPoster {
@Override
public void notifyFriendRequest() {
// implementation of notifyFriendRequest
}
@Override
public int numMediaTypes() {
return 5; // implementation of numMediaTypes
}
}
```
In this example, `FriendFinder` interface has a single method called `notifyFriendRequest()`, which does not return anything (`void`). The `MediaPoster` interface has a default method called `numMediaTypes()`, which returns the integer value 1 by default. The `MySocial` class implements both interfaces and provides implementations for both methods. The `numMediaTypes()` method is overridden to return 5 instead of the default value 1.
阅读全文