Java之方法调用
我们知道:Java方法有 有参方法和无参方法,有返回值方法和无返回值方法,那么在Java代码中,如何调用这些方法呢?
下文将一一道来,如下所示:
在Java中调用方法,非常的方便,只需输入方法名称,就可以调用方法,如:
System.out.println("This is my webSite Java265.com!");
例:
Java方法调用的示例分享
public class testClass {
public static void main(String[] args) {
int a = 888;
int b = 999;
int c = getMax(a, b);
System.out.println("最大值 = " + c);
}
/** 返回两个 int 数值的最大值 */
public static int getMax(int n1, int n2) {
int max;
if (n1 > n2)
max = n1;
else
max = n2;
return max;
}
}
/*
以上代码运行后,将输出以下信息
I:\E\Tmp>java testClass
最大值 = 999
*/
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


