I have some questions about the Java compiler.
My current directory is as follows.
├── Hoge.java ├── Sample.class ├── Sample.java ├── pattern01 │ └── com │ └── cat │ └── Hoge.class └── pattern02 └── com └── cat └── Hoge.class
----- Sample.java -----
import com.cat.Hoge; public class Sample { public static void main(String[] args) { System.out.println("hello!"); Hoge h = new Hoge(); h.call(); } }
----- pattern01 -----
package com.cat; public class Hoge { public void call() { System.out.println("com.cat"); System.out.println("pattern01"); } }
----- pattern02 -----
package com.cat; public class Hoge { public void call() { System.out.println("com.cat"); System.out.println("pattern02"); } }
I compiled Sample.java as follows.
$ javac -cp pattern01 Sample.java
And I execute it like this.
$ java -cp .:pattern01 Sample hello! com.cat pattern01 $ java -cp .:pattern02 Sample hello! com.cat pattern02
Both patterns01 and pattern02 usually complete.
But I compiled with pattern01. Why does the program usually end with pattern02?
What does the compiler check? Does the compiler check only the class name?
source share