1

so I came across following question:How does Java import work? and there was this Answer: Java's import statement is pure syntactical sugar. import is only evaluated at compile time to indicate to the compiler where to find the names in the code. You may live without any import statement when you always specify the full qualified name of classes. Like this line needs no import statement at all:

javax.swing.JButton but = new  javax.swing.JButton();

The import statement will make your code more readable like this: import javax.swing.; JButton but = new JButton();*

My Question: Lets say there was another package something like javax.swing2.* and lets say that this package contains the class with the same name we could wrtte something like

javax.swing.JButton but = new  javax.swing.JButton();
javax.swing2.JButton but2 = new  javax.swing2.JButton();

but how would java know which class do i mean if I only use import command:

 import javax.swing.*
import javax.swing2.*
JButton but = new  JButton();
JButton but2 = new  JButton();

0 Answers0