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.

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.

LANGUAGE: JAVA

CHALLENGE:

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.

SOLUTION:

public void clear() {
   super.clear();
   album.clear();
}

Add comment