Question: How do I access inner enum classes in another class? For example:

```
public class Foo {
    enum Bar {
        ONE, TWO, FOUR, EIGHT, SIXTEEN
    }

    // ...methods here
}

```

The class I am trying to access `Foo.Bar` in:

```
public class FooTest {
    private Foo f;

    @Before
    public void setUp() throws Exception {
        f = new Foo();
    }

    public void testCase1() {
        assertEquals(Bar.ONE, f.climbUp());
    }
}

```

I've tried `Foo.Bar.ONE`, `Bar.ONE` as well as making a new variable using `Foo.class.getDeclaredField("Bar")` but none of these seem to be working. `getDeclaredClasses()` seems to get me `$Bar` but I can't access anything from there.

**Update:** I'm not allowed to modify the class `Foo`

Answer: 
If the goal is to test it, but keep the enum in the default accessibility (`package-private`), which is implied by your inability to edit `Foo` and the title of the other class, then a common approach is to make the test in the same package. Meaning it can access the items with `default` visibility ([see here](http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html)).

The test:

```
package com.scratch;

public class FooTest {
    public static void main(String[] args) {
        System.out.println(String.valueOf(Foo.Bar.ONE));
    }
}

```

The other source:

```
package com.scratch;

public class Foo {
    enum Bar {
        ONE, TWO;
    }
}

```
You don't need to use reflection here. Just make the enum "static": 

```
public class Foo {
    static enum Bar {
        ONE, TWO, FOUR, EIGHT, SIXTEEN
    }

    // ...methods here
}

```

Then you can access it thru Foo.Bar.ONE