Hello.
I'm getting the correct output (I also tried adding another else if that checked if it was a Pig and then printed "Pig" and then also one that same case printed "Unknown animal" to no avail). Any hints?
Thanks
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) {
if (o instanceof Cow){
return "Cow";
}
else if (o instanceof Dog){
return "Dog";
}
else if (o instanceof Whale){
return "Whale";
}
else {
return "Unknown animal";
}//write your code here
}
public static class Cow {
}
public static class Dog {
}
public static class Whale {
}
public static class Pig {
}
}