Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There is another common usage of interfaces in Java - to tell a object has a specific use or characteristic. through the found objects and
There is another common usage of interfaces in Java - to tell a object has a specific use or characteristic. through the found objects and eat the ones that are edible First, let's define an interface called Foundobject with no methods at all. Those are all the objects we found in the woods: interface Foundobject now we define a second interface called Edible. We will use it just to denote if the object is edible or not. interface Edible public void eat () we create the interface Foundobject with the sole purpose to denote the objects of specific type, so we can put them in the same array. We create the Edible interface to mark which objects can be eaten Now, we will define the objects we find in the woods - fruit and stones. When we create the two objects (fruit and stone) we put implements Foundobject in the class declaration for all of them, and the ones we can eat also implement the Edible interface. We will first write the Fruit class and will write the Stone class in the subsequent question Write the Fruit class in the answer box below assuming that the interfaces have been done for you Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks For example Test Result Fruit orange - new Fruit("Orange")Yummy! you eat some Orange orange.eat); Fruit orange - new Fruit("Orange"); Orange System.out.println(orange); Answer (penalty regime: 0 %) 1 class Fruit implements 2
Step 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