0

I know this question has been asked a lot on importing two classes and instead omitting the import for both and calling full path whenever you want to use. My question related to this is can we just import one, use that one without the full path and write the full path of the other.

e.g.

import com.stackoverflow.FirstOne


firstOne ok = new FirstOne();
com.another.folder.firstOne isthisOk = new firstOne();
3
  • Yes, that is possible :) Infact imports are just to make developer life simple. Internally Java represents everything with fully qualified. Commented Jan 28, 2014 at 16:39
  • Yes, you can, why not Commented Jan 28, 2014 at 16:40
  • 3
    Is there any reason not to just try this for yourself? Commented Jan 28, 2014 at 16:40

4 Answers 4

4

You have to create a new object with a full package as well:

import com.stackoverflow.FirstOne;

FirstOne ok = new FirstOne(); 
com.another.folder.FirstOne isthisOk = new com.another.folder.FirstOne();

Note: Case is important

Sign up to request clarification or add additional context in comments.

Comments

1

Yes...that works.

You can use any number of classes by fully qualified name - and then import one to use by short name.

Comments

0

Why not, as log as you avoid confusing compiler, it will be happy.

Comments

0

Yes is posible if the class belongs to different packages, because the static type of the object is the name of a package + the name of the class.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.