Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java There is another common usage of interfaces in Java - to tell a object has a specific use or characteristic. Let's give a more
Java
There is another common usage of interfaces in Java - to tell a object has a specific use or characteristic. Let's give a more real-world example. You are trying to survival in the woods. You find different objects and put them in your backpack for later use. When you rest you go 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 f 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.printin(orange)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