불러오는 형으로 main 이 없다.
Printer.java |
public class Printer { public void print(){ String html = "<html><body> <h1>my html</h1> </body></html>" ; System.out.println( "html:" + html); } } |
test에 Printer 를 불러온다.
Hello.java |
public class Hello { public static void main(String[] args) { Printer printer = new Printer(); printer.print(); System.out.println( "Hello world!!!" ); } } |
실행
[root@localhost file]# javac Hello.java
[root@localhost file]# javac -d . test/Printer.java
[root@localhost file]# java Hello
html:<html><body> <h1>my html</h1> </body></html>
Hello world!!!