Skip to content

Instantly share code, notes, and snippets.

@fermopili
Created March 19, 2017 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fermopili/07d635d6b513d58a1fefed38b398455e to your computer and use it in GitHub Desktop.
Save fermopili/07d635d6b513d58a1fefed38b398455e to your computer and use it in GitHub Desktop.
com.javarush.task.task12.task1204;
/*
метод, который определяет, объект какого класса ему передали, и
выводит на экран одну из надписей: Кошка, Собака, Птица, Лампа.
*/
public class Solution {
public static void main(String[] args) {
printObjectType(new Cat());
printObjectType(new Bird());
printObjectType(new Lamp());
printObjectType(new Cat());
printObjectType(new Dog());
}
public static void printObjectType(Object o) {
if(o instanceof Cat)
System.out.println("Кошка");
if(o instanceof Dog)
System.out.println("Собака");
if(o instanceof Bird)
System.out.println("Птица");
if(o instanceof Lamp)
System.out.println("Лампа");
}
public static class Cat {
}
public static class Dog {
}
public static class Bird {
}
public static class Lamp {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment