-1

Here is the enum

class A {

    public A() {
    }
    public enum B{
        XYZ
        ABC
    }
    public enum c{
        DCE
    }
}

How should i call enum B and enum c in another class?

eckes
  • 10,103
  • 1
  • 59
  • 71
pals
  • 5
  • 4
  • Check out http://stackoverflow.com/questions/663834/in-java-are-enum-types-inside-a-class-static – eckes Feb 11 '15 at 20:06
  • My questions is how to decalre enum B in class c – pals Feb 11 '15 at 20:15
  • Do you mean "declare" as in declare the enum or declare a type? As with nested static classes you write "package.Class.NestedClass" (`A.B` in your case) to access the type. But if you struiggle to use that Enum, maybe you should declare it top level in the first place? – eckes Feb 11 '15 at 20:23
  • class A { public A() { } public enum B{ XYZ ABC } – pals Feb 11 '15 at 20:25
  • SO now how do i decalre it in class B the enum B – pals Feb 11 '15 at 20:25
  • You need a comma, pal. – eckes Feb 11 '15 at 20:25

3 Answers3

2

Import the Enum, use it.

import A.B;
...
B b = B.XYZ;
runDOSrun
  • 10,359
  • 7
  • 47
  • 57
1

You can call like following

A.B.XYX
A.c.DCE
Ahmet Karakaya
  • 9,899
  • 23
  • 86
  • 141
0

1.Just use class B extends A so the class B can see all the Objects of class A If you dont know how extend works see this link

2.Also you can use import to import A class

  • if you work in eclipse you should refer and the package name of A

  • If you work in NetBeans something similar

  • If you don't work(you work on notepad..) just use import A

    Import a custom class in Java

    public class B extends A{
       //The class B can see the Objects of class A if they are not      **private** 
     }
    

What,why,and how enums work http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

Community
  • 1
  • 1
crAlexander
  • 376
  • 1
  • 2
  • 12