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

  • Home
  • SEARCH
  • 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 7491721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:06:40+00:00 2026-05-29T16:06:40+00:00

Thanks to stackoverflow i finally understood that i need to compile from the source

  • 0

Thanks to stackoverflow i finally understood that i need to compile from the source directory when m trying to compile a file which has a object of another class of the same package declared in one of its method. ex-

package p1;
public class accesslevel
{
    int n=2;
    private int pri_n=3;
    protected int pro_n=4;
    public int pub_n=5;
    public accesslevel()
    {
                System.out.print("\nin accesslevel constructor");               
        System.out.print("\nn="+n);
        System.out.print("\nprivate n="+pri_n);
        System.out.print("\nprotected n="+pro_n);
        System.out.print("\npublic n="+pub_n);
    }
}

package p1;
class samepckp1test
{
    public static void main(String args[])
    {
        accesslevel a=new accesslevel();
    }
}  

But i dont get why i need to do that?Can someone help me understand why i need to move one level up?

  • 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-29T16:06:42+00:00Added an answer on May 29, 2026 at 4:06 pm

    Because packages in Java are mapped to directories.

    So, if you have a p1 directory for your samepckp1test class like this:

    p1
       -> samepckp1test.java
       -> accesslevel.java
    

    Then java expects you to be on p1‘s parent directory to compile to compile p1 package. (p1 package contains samepckp1test and accesslevel classes).

    If you want your classes to be in the default package (no package declaration at all which I don’t recommend) you can compile them from their container directory (instead of the parent directory in your example).

    Rule is: classes are expected to be found inside directories following their package declaration.

    That is, if your class MyClass is in com.stackoverflow.test package, your class source is expected to be found in:

    com/stackoverflow/test/MyClass.java
    

    So you need to be in directory containing the com subdirectory.

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

Sidebar

Related Questions

I have a simple file uploader, which thanks to stackoverflow is now fully working,
Now that I can make useful user controls in WPF (thanks to this stackoverflow
First, thanks for all the help I've received so far from StackOverflow. I've learned
I have an admin page for a WordPress plugin that, thanks to the stackoverflow
thanks to help from stackoverflow posters I have set up some oop javascript. However,
First, thanks for the StackOverflow team, cause it's a very useful website, since i'm
Thanks to the answer on this stackoverflow question I was able to get the
Thanks to reading about error handling on StackOverflow , I discovered Mz-Tools. However, I
Thanks to a Q&A on stackoverflow. I just found out how to determine the
I have this regex thanks to another wonderful StackOverflow user /(?:-\d+)*/g I want it

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.