title: how to run java class file in cmd line
body: <p>my 2 classes are like this:</p>
  
  <pre><code>package p;
  class A{
    public static void main(String[] args){
      B b = new B("haha");
      b.run();
      //System.out.println("he");
    }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>package b;
  class B{
    String s;                             
    public B(String s){   
      this.s = s;
    }                             
  
    public void run(){
      System.out.println(s);              
    }                                     
  }
  </code></pre>
  
  <p>I fail to compile these 2 files using <code>javac a.java b.java</code>, and the error is:</p>
  
  <blockquote>
    <p>a.java:4: cannot find symbol<br>
    symbol  : class B 
    location: class p.A<br>
        B b = new B("haha");<br>
        ^<br>
    a.java:4: cannot find symbol<br>
    symbol  : class B<br>
    location: class p.A<br>
        B b = new B("haha");<br>
                  ^<br>
    2 errors  </p>
  </blockquote>
  
  <p>while after removing <code>package p;</code>,<code>javac a.java b.java</code> runs well.</p>
  
  <p>So, how can I compile and run class A with the <code>package p;</code>?</p>
  
  <p>======Edit=======<br>
  Thanks for all your reply,and finally I made my classes run by changing my files like this:</p>
  
  <p>.<br>
  ├── b<br>
  │   ├── B.class<br>
  │   └── B.java<br>
  └── p<br>
      ├── A.class<br>
      └── a.java  </p>
  
  <p>and a.java:</p>
  
  <pre><code>package p;
  
  import b.B;
  
  class A{
    public static void main(String[] args){
      B b = new B("haha");
      b.run();
      //System.out.println("he");
    }
  }
  </code></pre>
  
  <p>B.java:</p>
  
  <pre><code>package b;
  public class B{
    String s;
    public B(String s){
      this.s = s;
    }
  
    public void run(){
      System.out.println(s);
    }
  }
  </code></pre>
  
  <p>Things need to pay attention to :</p>
  
  <ul>
  <li>class B must be public</li>
  <li>should import B when trying to use it in class A</li>
  </ul>