Reputation: 391
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();
Upvotes: 0
Views: 1684
Reputation: 2444
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.
Upvotes: 0
Reputation: 812
Why not, as log as you avoid confusing compiler, it will be happy.
Upvotes: 0
Reputation: 6667
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
Upvotes: 4
Reputation: 41210
Yes...that works.
You can use any number of classes by fully qualified name - and then import one to use by short name.
Upvotes: 1