I'm supposed to write a class sky with a method toString, and a subclass cloud with a method toString that overwrites the original one, and then a detect class to check if the variable is from the class sky or clouds, but it does not work. Please help:
class Sky{
String toString() {
return "sky";
}
}
class Cloud extends Sky{
String toString() {
return "cloud";
}
}
void detect(Sky x) {
if (x.toString().equals("sky")){
System.out.println("Got a sky!");
} else if (x.toString().equals("cloud")){
System.out.println("Got a cloud!");
}
}