96.3k views
2 votes
Assume the existence of a Phone class with a method, clear, that clears the phone's memory-- its phone book, list of call, text messages, etc. Assume also, a subclass CameraPhone with an instance variable, album, of type PhotoAlbum-- which has a method, also called clear that clears its contents. Override the clear method in CameraPhone to clear the entire phone, i.e., to invoke the clear method of Phone (the superclass), as well as invoking the clear method of the album instance variable.

User SWAT
by
5.0k points

1 Answer

4 votes

Answer:

The following are the code.

//define function

public void clear() {

//override clear method

super.clear();

album.clear();

}

Step-by-step explanation:

In the above code of the Java Programming Language, we define the void type function "clear()" which is used to clear the elements of the list or set, inside the following function we override the clear() function. Firstly, we set clear() with super then, we set clear() method with album in CameraPhone for clear the photos.

User Nakeema
by
5.6k points