Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java8 programming, interfaces,polymorphism,inheritance, convert uml to Java8 code,and output as expected. please explain in detail Interfaces declare methods that will describe a behaviour an object
Java8 programming, interfaces,polymorphism,inheritance, convert uml to Java8 code,and output as expected. please explain in detail
Interfaces declare methods that will describe a behaviour an object may have. When a class implements the interface it will need to define the methods that have been declared to satisfy the relationship. public interface Talkable { //outputting what the object is saying public void talk(); //What the object should say, if it can understand words public void script (String[] words); } Wait... aren't they the same thing? These two concepts are oftenly confused of being the same thing when really they are used in different scenarios. Class heirarchy infers to a clear generalisation of a type while interfaces infers to an shared behaviour between types. Example 1: a Dog and Cat both exhibit some way of talking but the noise they emit is different and it doesn't make sense for Cat and Dog to be in the same heirarchy. Example 2: Person can interact with other Person objects but also Furniture, Singage and Animal objects. It is clear are not suitable to be in the same class heirarchy but can facilitate a method of Interaction. Unlike class inheritance where a class can only inherit from only a single class, a class can implement as many interfaces it wants. The following is where a Person class has specified it will implement a number of interfaces. public class Person implements Swim, Talk, Jump, Run Similar to abstract classes, when a class states it will implement an interface it will need to implement all methods declared. Question 4: Interacting with objects Given the following UML diagram, implement the following interface and classes. Your classes must be able to interact with any object that implements the Interactable interface. When an object invokes talkTo, it will use Strings from the initiation script, for every elements in the initiation script the target object will respond with Strings in the response script. > Interactable +talkTo(thing:Interactable): void +responseScript(): ListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started