Question: Define an interface TwoStrings Oper declaring a function apply which takes two strings and returns a string. Then, define four classes implementing this interface,

Define an interface TwoStrings Oper declaring a function apply which takes two 


Define an interface TwoStrings Oper declaring a function apply which takes two strings and returns a string. Then, define four classes implementing this interface, where the operation on strings returns: their concatenation (class Concat); their concatenation, but in the reverse order(class Concat Rev); a string consisting of the first letters of the two strings (class Initials); their concatenation, but separated by a separator passed to the constructor (class Separ). The following main function public static void main(String[] args) { TwoStringsOper [] a = { }; new Concat(), new ConcatRev(), new Initials (), new Separ(" loves ") for (TwoStringsoper op: a) { download InterS.java System.out.println(op.apply("Mary", "John")); } } should print: MaryJohn JohnMary MJ Mary loves John

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres how you can define the interface TwoStringsOper and the four classes that implement this inter... View full answer

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 Physics Questions!