1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * Return stuff.
19 */
20public class Main {
21    public static void main(String[] args) {
22
23        System.out.println("pick 1");
24        pickOne(1).run();
25        System.out.println(((CommonInterface)pickOne(1)).doStuff());
26
27        System.out.println("pick 2");
28        pickOne(2).run();
29        System.out.println(((CommonInterface)pickOne(2)).doStuff());
30
31        System.out.println("pick 3");
32        pickOne(3).run();
33    }
34
35    public static Runnable pickOne(int which) {
36        Runnable runme;
37
38        if (which == 1)
39            runme = new ClassOne();
40        else if (which == 2)
41            runme = new ClassTwo();
42        else if (which == 3)
43            runme = new ClassThree();
44        else
45            runme = null;
46
47        return runme;
48    }
49}
50
51class ClassOne implements CommonInterface, Runnable {
52    public void run() {
53        System.out.println("one running");
54    }
55    public int doStuff() {
56        System.out.println("one");
57        return 1;
58    }
59}
60
61class ClassTwo implements CommonInterface, Runnable {
62    public void run() {
63        System.out.println("two running");
64    }
65    public int doStuff() {
66        System.out.println("two");
67        return 2;
68    }
69}
70
71class ClassThree implements Runnable {
72    public void run() {
73        System.out.println("three running");
74    }
75}
76
77interface CommonInterface {
78    int doStuff();
79}
80