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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:51:27+00:00 2026-06-12T16:51:27+00:00

If i have a class inside a package say mypackage.myclass and want to access

  • 0

If i have a class inside a package say mypackage.myclass and want to access a package’s class that is in the same folder as the package’s root (not inside the package) say anothepackage.anotherclass how can I actually do so?

Example presented in code:

// directories are preceded by a DIR, files are preceded by a CLASS
// any level deeper is preceded by a [Tab]
DIR mypackage
    CLASS myclass
    DIR myinnerpackage
        CLASS myinnerclass
DIR anotherpackage
    CLASS anotheclass
CLASS yetanotherclass
DIR org
    DIR apache
        DIR commons
            DIR exec
                CLASS DefaultExecutor

Inside the file myclass:

package mypackage;

public class myclass{
    // simplest example  code I can come up with
    org.apache.commons.exec.DefaultExecutor exec = new org.apache.commons.exec.DefaultExecutor();
}

Why does this piece of code not work for me?

Generally how can myclass access anotherclass or yetanotherclass and how can myinnerclass access them as well? Try to refrain for imports as I want to use certain members of each class only (some variables have same names and will get things messed)! Thanks in advance!

  • 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-06-12T16:51:28+00:00Added an answer on June 12, 2026 at 4:51 pm

    Java right?

    inside myClass

    import anotherPackage.anotherClass;
    

    and then inside your myClass you can just use

      anotherClass ac=new anotherClass();
    

    then using object “ac” you can access any of anotherClass properties.

    you might want to read about packages and imports

    Edit
    without using imports
    i you can use concept of fully qualified name try like

    anotherPackage.anotherClass ac=new anotherPackage.anotherClass()
    

    then use ac toacees anotherClass properties

    by the way you mentioned, different classes have some same variables and imports can mess up stuff. Java works around objects, same names aint really gonna messup. even if some variables are static you will be using classnames.staticVar to access. so not much of messing up. 🙂

    UPDATE :
    the discussion below was moved to chat as it was getting comprehensive
    some usefull snippets from chat

    Askee was facing classpath issues

    CLASSPATH , as the name suggests it is the path to class.
    when we compile a java file, the compiler will look for the resources that the class needs in current directory and on the classpath.
    everything cann not be in same directory (actually it can be, 🙂 ) , so we use

    set CLASSPATH
    

    to set classpath and where else to look for classes

    in the question the ckass myClass was not getting compilec as

    org.apache.common.exec.DefaultExecutor was not in classpath
    

    suggested to set parent directory on classpath to have it work

    javac -classpath %cd%\.. myclass.java
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Menu and inside that class I want to place
I have a package with some classes inside D:\ProjectGsc\ . The package root folder
i have a class that uses a proxy class inside to call a service
I have a class that holds another objects inside it (List, Set and objects
I have a class that is viewcontroller and I'v putted it inside of tabbar.
I have a large number of records, say around 4,000,000, that I want to
I have this class that implements FilenameFilter package Logic; import java.io.File; import java.io.FilenameFilter; public
I have several web services in the same package that throw a custom exception.
I have a class that needs access to urllib2, the trivial example for me
I have a class that is using a stackpanel which then gets called inside

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.