1

I have made a file A.java and another B.java. A and B are in the same folder. B has

  A a = new A(); 

How do I import A to B ?

I am not using any ide. Running it on hadoop framework

4
  • 2
    Classes in the same package are visible to each other you don't need to import them. In order to import all the functionality of A class into B class you can extend A class into B class. Jul 24, 2018 at 22:27
  • @M.leRutte classes can be in the same folder but have different package statements. Try creating a package 'test' and putting 2 classes in there A and B, for first class write package test.abc; for second package test.ab; Btw, if you use intellij, it has lots of package related bugs. But the code will compile and run.
    – Coder-Man
    Jul 24, 2018 at 22:27
  • Possible duplicate of Java importing class in the same package
    – uğur taş
    Jul 24, 2018 at 23:09
  • Tips: use the terms for package (represented on the local file system as a directory, and in a Jar as a resource path), directory (a location on the local file system that can contain files) and folder (a graphical OS' representation of a directory) correctly. Programming is hard enough already without 'loose' use of terms. Jul 24, 2018 at 23:43

2 Answers 2

0

image

No need of importing files. Just compile and run. As in the picture 1 you can you can compile both files and run the class with the main method . In my case my main method is in DogTest.java file in or You can just compile your java file which includes the main() method and run.

0

Classes that are in the same package do not need to import from other classes in the package, provided that the class isn't private. So in your case, you shouldn't need to worry about importing, as A is, by default, imported to B so long as A isn't private.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.