JavaSE review diary: method invocation and method overloading

WBOY
Release: 2016-07-30 13:30:55
Original
1584 people have browsed it

/* * 方法的调用和方法重载 *//* * 什么是方法? * 方法就是一个有名字的代码段; * 方法的调用: * 在方法里调用另外一个方法里面的东西就是方法调用; * 或者可以认为"另外一个方法的名字()"就是方法的调用; * 方法的重载: * 就是在main方法外写了多个方法名相同,但是形参列表不同的方法,在main方法中调用这个方法时括号内写上实参,程序会默认调用实参和调用方法里形参相匹配的方法; */// 方法形式和方法的类部调用/*public class JavaSE{ public static void main(String[] args){ JavaSE.Method_1();//方法的调用就是:类名.方法名(实参列表); Method_2(1,2);//main方法调用这个类里面的静态方法也可以这么写; Method_3(5,5); } public static void Method_1(){ System.out.println( "我很帅" ); } public static void Method_2(int a,int b){ int c = a + b; System.out.println( c ); } public static int Method_3(int e,int d){//注意这里static后面跟的是int,是返回值类型,这是方法最后必须写return语句; int f = e + d; System.out.println( f ); return f;//return语句在有返回值类型的时候必须有返回值,不然会报错; } } *///------------------------------------------------------------------------- // 方法的重载publicclass JavaSE{ publicstaticvoid main(String[] args){ Method_4(1,1.0);//这里1是int型的,1.0是double型的,结果是2.0,结果自动转换为double型 Java.sum(2,1);//调用外部类的方法必须是:外部类名.方法名(实参列表); } publicstaticvoid Method_4(int a,int b){ int c = a + b; } publicstaticvoid Method_4(int a,double b){ System.out.println( a + b ); } } class Java{ publicstaticvoid sum(int a,int b){ System.out.println( a + b ); } publicstaticvoid sum(int a,double b){ System.out.println( a - b ); } }
Copy after login

The above introduces the JavaSE review diary: method invocation and method overloading, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!