当前位置:网站首页>2021-04-16 method overload parameter transfer
2021-04-16 method overload parameter transfer
2022-06-23 10:07:00 【Deer like deer】
Method overloading
Overloading is in a class , Have the same function name , But functions with different parameters
Method overload rules :
- The method name must be the same
- Parameter list must be different ( The number is different. , Or of different types , Different parameter sorting lists, etc )
- Methods can have the same or different return types
- It's not enough to be an overload of a method just because the return type is different
public class Demo3 {
public static void main(String[]args){
int max = max(10,20,30);
System.out.println(max);
}
// Than the size
public static int max(double num1,double num2){
return 0;
}
// Than the size
public static int max(int num1,int num2){
return 0;
}
// Than the size
public static int max(int num1,int num2,int num3){
return 0;
}
}
Command line arguments
Sometimes I want to give him a message when I run a program , This depends on passing command line arguments to main() Function implementation
Variable parameters
Java Support passing variable parameters of the same type to a method
In the method declaration , Add an ellipsis after the specified parameter type
Only one variable parameter can be specified in a method , It must be the last parameter of the method , Any ordinary parameter must be declared before it
public class Demo4 {
public static void main(String[]args){
Demo4 demo4 = new Demo4();
demo4.test(1);
}
public void test (int...i){
System.out.println(i[0]);
}
}
边栏推荐
- RBtree
- After installing these five plug-ins, pycharm can be used for takeoff!
- RT-Thread 添加 msh 命令
- 大作业合集
- Subscript operator of map
- XML related interview questions
- 2021-04-12 the first implementation of linked list!!!
- 天龙八部TLBB系列 - 网单服务端各目录文件说明【超详细】
- Alimentation des animaux de compagnie basée sur stm32
- 开发者,你对云计算可能有些误解
猜你喜欢
随机推荐
16. system startup process
SQL writing problem to calculate the ring ratio of the current month and the previous month
How does thymeleaf get the value of the request parameter in the URL?
135137138445 unable to remotely connect to the database due to disabling
Copilot免费时代结束!正式版67元/月,学生党和热门开源项目维护者可白嫖
同花顺推荐么?手机开户安全么?
Gorm advanced query
Thin film interference data processing
谷贱伤农,薪贱伤码农!
xml相关面试题
laravel8 beanstalk 使用说明
Bioinformatics | 基于相互作用神经网络的有效药物-靶标关联预测
The second Tencent light · public welfare innovation challenge was launched, and the three competition topics focused on the social value of sustainable development
启明星辰华典大数据量子安全创新实验室揭牌,发布两款黑科技产品
JS教程之 什么是 JSX?为什么我们需要它?
Shengshihaotong enables high-quality development with industrial Digitalization
Confessing with Snake games (with source code)
解决audio自动播放无效问题
Servlet-02 lifecycle
Typora set up image upload service







