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 3608074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:27:22+00:00 2026-05-18T21:27:22+00:00

The one class per file rule in Java has me a bit confused. I

  • 0

The one class per file rule in Java has me a bit confused. I writing an Android app and trying to implement the accepted answer to this question:

Common class for AsyncTask in Android?

which calls for an interface definition which class A implements and class B accepts as an argument to its constructor.

So I need an A.java and a B.java, but where does the interface go? Does it need a separate java file itself? Do I have to define it inside both A and B? If not how to import it?

Also I will have about 10 different AsyncTask classes, but I don’t want to bother creating a new file for each one. What would you recommend? Is there a way to put all 10 classes in one file? Or should I create a big if/then block inside the class and pass an argument telling it which of the 10 different tasks I want it to do?

  • 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. Editorial Team
    Editorial Team
    2026-05-18T21:27:23+00:00Added an answer on May 18, 2026 at 9:27 pm

    You have to place it in AsyncTaskCompleteListener.java. If it is in the same package, then there is no need to import it. If in a different package, you can import it using the import statement.

    I’d suggest reading a java tutorial before going further.

    As for the 10+ classes – you can use public static class inside another class. This would work, but having a file for each class is something you should get used to – it is the preferred option. The inner static class is used only if a logical relating of the inner classes exists to their owning class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like the Java convention of having one public class per file, even if
I'm used to the Java model where you can have one public class per
I used to have one class for one file. For example car.cs has the
I love to organize my code, so ideally I want one class per file
Let's say I have one class Foo that has a bunch of logic in
Is it good practise to have multiple class definitions in one file? or is
I have memory mapped a large formatted (text) file containing one integer per line
I am asked by one of colleague about the Throwable class in java API.
I have one class that needs to grab an attribute that is set in
Let's say you've inherited a C# codebase that uses one class with 200 static

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.