We create the interface Foundobject with the sole purpose to denote the objects
ID: 3746252 • Letter: W
Question
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 one we can eat also implement the Edible interface. Write the Stone class in the answer box below assuming that the interfaces and the Fruit class have been done for you For example: Test Result Stone s = new Stone("Stone"); | Stone System.out.println(s);Explanation / Answer
AS You need to give only Stone class below is the code and additionally i have written FoundObject interface and main method for testing the output but u might need only Stone class
//save the below code as Stone.java
/**
* Stone class which implements FoundObject
*/
public class Stone implements FoundObject{
private String name;
//constructor for setting
public Stone(String s){
this.name = s;
}
//toString for printing object
@Override
public String toString() {
return this.name;
}
}//end of Stone class
//Below are additionally written for testing purpose
//FoundObject.java
/*
FoundObject interface for grouping the derivable from it
*/
interface FoundObject{}
//end of FoundObject
//Test class with main method
public class Test{
public static void main(String[] args) {
FoundObject s = new Stone("Stone");
System.out.println(s);
}
}//end of Test class
//On running Test.java it will produce
Stone
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.