Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:06:43+00:00 2026-05-11T07:06:43+00:00

I have 2 files which are interacting with each other. I wanted to define

  • 0

I have 2 files which are interacting with each other. I wanted to define an enum to make the code more readable, but if I define it in file 1, file 2 complains about having no knowledge of said enum. If I define ii in file 2, file 1 does the same. I am defining it as public too.

The solution was to define the enum in both files, but this doesn’t seem right to me. Not only is it redundant, but I fear it may cause some conflict, even if the types have the same items.

What is the veredict on this? Am I doing something wrong or worrying too much?

EDIT

Well, given the comments here I found an alternative which seems to be doing what I want without having to create a new file. I had:

file 1

class myClass1 {     public enum MyEnum     {         ...     }     ... } 

file 2

class myClass2 {     public enum MyEnum     {         ...     }     .... } 

Now, I have:

file 1

enum myEnum {     ... }  ...  class myClass1 {      ... } 

file 2

class myClass2 {      ... } 

I didn’t want to create another file just for the enum, so this works for me. Well, as long as there is nothing wrong with it, which I think there isn’t.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:06:44+00:00Added an answer on May 11, 2026 at 7:06 am

    You definitely shouldn’t define the enum in both locations. I recommend defining the enum in its own file with public accessibility. Then everyone should have no trouble accessing it. However, assuming that you want to define the enum in one of the two classes, I’ll continue…

    You have to import the enum or use its fully qualified name. Assuming you are in the package com.stackoverflow, your classes should look like this, in the first file:

    package com.stackoverflow;  public class A {     public enum MyEnum {       ONE,TWO,THREE;     }      ... } 

    and in another file:

    package com.stackoverflow;  import com.stackoverflow.A.MyEnum;  public class B {    public void test(MyEnum mine) {     ...   }    ... } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list of files which contain particular patterns, but those files have been
I have a task, which I know how to code (in C#), but I
I have a really modular application in which modules interact with each other for
I have files which have many empty cells which appear as NaNs when I
I have two files which both contain a list of words. Is there an
I have multiple excel files which I open as datatable I want to merge
I have some .csv files which I'm using as part of a test bench.
We have certain configuration files which we want to be in version control as
I have two batch files which is used to run a large C++ build,
I have various PHP files which data is Posted to (like the password when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.