Jump to content

Como importar class de um nivel anterior?


Recommended Posts

Posted

Viva,

imaginemos que tenho os seguintes níveis de pastas:

pasta/pasta1

em "pasta1" tenho o ficheiro file1.java e na "pasta" tenho file.java

como consigo fazer o import de file.java no ficheiro file1.java?

Posted
// File1
package pasta.pasta1;

import pasta.File;

public class File1 {
    //...
}

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Posted

não esta a resultar, talvez eu não me tenha explicado bem

mas no meu caso o "pasta" é o directoria principal do programa (default), será aconselhável criar um package para colocar todo o projecto e depois dentro desse package criar os outros? (pois desta forma acho que funcione)

obrigado

Posted

será aconselhável criar um package para colocar todo o projecto e depois dentro desse package criar os outros? (pois desta forma acho que funcione)

Sim 😄

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.