Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

2 The causes and effects of demand shocks and supply shocks

Answered: 1 week ago