Question: Question 1: a.Declare an interface Filter that has a method accept() which accepts as parameter an Object, and return b. as a Boolean. c.Provide an

Question 1:

a.Declare an interface "Filter" that has a method "accept()" which accepts as parameter an Object, and return

b. as a Boolean.

c.Provide an abstract class ShortWordFilter that implements the interface "Filter".

d.Extend two concrete classes LessThanFive and LessThanTen from ShortWordFilter class, such that both have an ArrayList of type String to store the words.

e.Define a static method "collectAll" that accepts as parameters two arguments, an arraylist of type String and a reference of type Filter. The method returns an arraylist of type Filter containing two polymorphic references to objects of the subclasses containing ArrayList filled with words that are accepted by the given filter.

f.Then write testclass that reads all words from System.in, puts them into an ArrayList, defines a polymorphic reference to interface, calls collectAll(), and prints a list of the short words.

Question 2:

Can we implement more than on interfaces in java? If yes, then demonstrate the concept with help of java code example?

Creating two interfaces with at least one method in each.

Implementing these interfaces in class with a main function to test function feedback of the interfaces.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!