No matter what I do I can’t get this to compile. If I leave the bottom part alone, incorrect values. If I use an else statement (or even else if) I get missing return statement }. When it’s clearly there. So then I tried doing instanceof, fo the end and it tells me that’s an unreachable statement. So where do I go from there?
package com.codegym.task.task12.task1205;
/*
Animal identification
*/
public class Solution {
public static void main(String[] args) {
System.out.println(getObjectType(new Cow()));
System.out.println(getObjectType(new Dog()));
System.out.println(getObjectType(new Whale()));
System.out.println(getObjectType(new Pig()));
}
public static String getObjectType(Object o) {
//write your code here
if (o instanceof Cow){
System.out.println(o.getClass().getSimpleName());
}
else if (o instanceof Dog){
System.out.println(o.getClass().getSimpleName());
}
else if (o instanceof Whale){
System.out.println(o.getClass().getSimpleName());
}
else{
return "Unknown Animal";
}
}
public static class Cow {
}
public static class Dog {
}
public static class Whale {
}
public static class Pig {
}
}