Created
March 19, 2017 12:07
-
-
Save fermopili/07d635d6b513d58a1fefed38b398455e to your computer and use it in GitHub Desktop.
com.javarush.task.task12.task1204;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
метод, который определяет, объект какого класса ему передали, и | |
выводит на экран одну из надписей: Кошка, Собака, Птица, Лампа. | |
*/ | |
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