test.java
package com.rectanglesystems.demo;
public class test {
String getString()
{
String msg = new String("hello world");
return msg;
}
public static void main(String[] args) {
test t = new test();
String msg = t.getString();
System.out.println(msg);
}
}
编译:
> javac -d . test.java
这会在当前目录下生成子目录 com/rectanglesystems/demo,在这个子目录下有一个test.class的文件
运行:
> java com.rectanglesystems.demo.test
输出:
hello world
由于java的对象传递方式是引用,这里getString函数返回字符串是没有问题的。