R rongercao Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-24 #1 java中怎么自定义函数,就象delphi中那样定义一个字符串相加的函数,然后在程序中调用. 最好有源代码?
F fangmaohua Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-24 #2 java里不能在类外面定义 函数 只能 在一个公共 类内定义
B beginfreely Unregistered / Unconfirmed GUEST, unregistred user! 2003-06-27 #4 class Strings{ String My; String Name; Strings(String Str1,String Str2){ My = Str1; Name = Str2; } } public class StringAdd { public static void main(String[] args) { String MyName; Strings S = new Strings("My","Name"); MyName = S.My+S.Name; prt(MyName); } static void prt(String s) { System.out.println(s); } }
class Strings{ String My; String Name; Strings(String Str1,String Str2){ My = Str1; Name = Str2; } } public class StringAdd { public static void main(String[] args) { String MyName; Strings S = new Strings("My","Name"); MyName = S.My+S.Name; prt(MyName); } static void prt(String s) { System.out.println(s); } }
J jackshow Unregistered / Unconfirmed GUEST, unregistred user! 2003-07-10 #5 class Strings{ private String Str1; private String Str2; public static StringAdd(String Str1,String Str2) { Str1 += Str2; } } public class StringAdd { public static void main(String[] args) { String str1; String str2; Strings str = new Strings() String str3 = str.StringAdd(str1,str2) System.out.println(str3); } }
class Strings{ private String Str1; private String Str2; public static StringAdd(String Str1,String Str2) { Str1 += Str2; } } public class StringAdd { public static void main(String[] args) { String str1; String str2; Strings str = new Strings() String str3 = str.StringAdd(str1,str2) System.out.println(str3); } }
C clever_boy_2000 Unregistered / Unconfirmed GUEST, unregistred user! 2003-07-10 #6 pakage sa; public class t1{ public static String addString(String s1,String s2){ return s1+s2; } } ...... import sa; public class t2{ public static void main(String[] arg){ System.out.println(sa.addString("hello","world")); } }
pakage sa; public class t1{ public static String addString(String s1,String s2){ return s1+s2; } } ...... import sa; public class t2{ public static void main(String[] arg){ System.out.println(sa.addString("hello","world")); } }
R Rolaldo Unregistered / Unconfirmed GUEST, unregistred user! 2003-08-07 #8 甚至可以在公共类中定意一个返回类的static instance的方法这样就可以不用将类中的方法定义成static的了。