Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Integer i = new Integer(42);
- Double d = new Double(3.14156);
- String s = new String ("All your base are belong to us!");
- Object o = null;
- handle(o);
- o = i;
- handle(o);
- o = d;
- handle(o);
- o = s;
- handle(o);
- }
- private static void handle(String arg) {
- System.out.println("It's a string!");
- }
- private static void handle(Number arg) {
- System.out.println("It's a number!");
- }
- private static void handle(Double arg) {
- System.out.println("It's a double!");
- }
- private static void handle(Object arg) {
- System.out.println("no idea what it is...");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement