首页 > 试题广场 >

下面有关重载函数的说法中正确的是()

[单选题]
下面有关重载函数的说法中正确的是()
  • 重载函数必须具有不同的返回值类型
  • 重载函数形参个数必须不同
  • 重载函数必须有不同的形参列表
  • 重载函数名可以不同
推荐
重载:必须同名函数;必须参数表不同(包含参数个数不同;参数类型不同;或参数个数与类型都不同)
编辑于 2015-02-04 21:06:26 回复(6)
函数的重载即同一个函数名称,但是函数的参数个数和参数类型不同。所谓“重载”,其实就是“一物多用”。
发表于 2015-03-31 22:24:44 回复(0)

①重载是指不同的函数使用相同的函数名,但是函数的参数个数或类型不同。调用的时候根据函数的参数来区别不同的函数。

②覆盖(也叫重写)是指在派生类中重新对基类中的虚函数(注意是虚函数)重新实现。即函数名和参数都一样,只是函数的实现体不一样。

发表于 2019-08-26 09:31:36 回复(0)
Java允许同一个类里定义多个同名方法,只要形参列表不同就行。

如果同一个类中包含了两个或两个以上方法的方法名相同,但形参列表不同,则被称为方法重载。

 

Java程序中确定一个方法需要的三个要素:

1、调用者:就是方法的所属者,可以是类或者是对象;

2、方法名:方法的标识;

3、形参列表:当调用方法时,系统将会根据传入的实参列表匹配。

 

重载方法的要求是两同一不同:即同一个类中方法名相同,参数列表不同。至于方法de的其他部分,如方法返回值类型、修饰符等,与方法重载没有任何关系。
--------------------- 
作者:活抓一只程序员 
来源:CSDN 
原文:https://blog.csdn.net/qq_36473318/article/details/91353930 
版权声明:本文为博主原创文章,转载请附上博文链接!
发表于 2019-06-11 16:18:07 回复(0)
选C
重载,只有两个要求,方法名一致,形参列表一致。其他都不可判定。
发表于 2018-06-29 19:27:12 回复(0)
不是C吗?B中参数个数可以相同啊
发表于 2017-03-08 12:50:02 回复(1)
重载: 参数表 必须 不同( 参数个数不同or参数类型不同or参数个数与类型都不同),与 返回值类型值无关
发表于 2016-09-11 08:50:34 回复(0)
c
发表于 2020-06-11 00:05:17 回复(0)
答案说选D

发表于 2020-01-09 19:26:17 回复(0)
重载与返回值类型没有关系.不是说重写要求返回值类型相同,就要求重载是不同的
参数列表包括,参数类型不同 或 参数个数不同 或者 二者都不同;不是必须个数相同
关于d啊,名都不一样,叫什么重载啊
发表于 2019-08-11 17:17:00 回复(0)
C
发表于 2019-05-05 15:45:33 回复(0)
重载的参数列表各不相同
发表于 2019-05-04 11:13:03 回复(0)
重载函数名必须相同,参数个数必须相同,参数类型可不同,返回值类型不能作为重载的判断。
发表于 2019-04-24 16:06:07 回复(0)
加“const”和“不加const”的也是重载关系,这么看四个选项没有一个是对的
发表于 2019-04-14 10:46:26 回复(0)
函数的重载: 1、同一个类 2、同名函数 3、参数个数不同或者参数类型不同 4、java是严谨性语言,如果函数出现的调用不准确性,会编译失败
发表于 2019-03-20 09:41:18 回复(0)
重载:
    必须同民函数,
    必须参数表不同:包含参数个数不同;参数类型不同;或参数个数与类型都不同

发表于 2019-03-03 13:51:13 回复(0)
参考这篇文章

最近在准备复习java,拿牛客网 Java 题目来练习,发现自己基础真的很薄弱。所以想通过share来巩固自己的基础知识。

https://www.nowcoder.com/profile/135782706/test/21149629/1092

关于重载的说法正确的是

  1. 重载函数必须具有不同的返回值类型
  2. 重载函数形参个数必须不同
  3. 重载函数必须有不同的形参列表
  4. 重载函数名可以不同

https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

The Java programming language supports overloading methods, and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists (there are some qualifications to this that will be discussed in the lesson titled "Interfaces and Inheritance").

方法可以拥有相同的名字,如果它们之间拥有不同的参数(形参:parameters)列表。

public class DataArtist { ... public void draw(String s) { ... } public void draw(int i) { ... } public void draw(double f) { ... } public void draw(int i, double f) { ... }
}

You cannot declare more than one method with the same name and the same number and type of arguments, because the compiler cannot tell them apart.

The compiler does not consider return type when differentiating methods, so you cannot declare two methods with the same signature even if they have a different return type.

你不能声明两个相同名字和相同数目和类型的参数,因为编辑器无法区分它们。

编辑器并不考虑区分两个拥有相同方法签名并拥有不同返回值的方法。

重载函数并不要求不同的返回类型(1.),和形参个数(2.),但要求函数名要相同(4.)。

什么是override(覆盖)

https://www.geeksforgeeks.org/overriding-in-java/

When a method in a subclass has the same name, same parameters or signature and same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.

当一个子类有名字相同,相同的参数/方法签名,相同的返回值/sub-type在它的super-class中作为一个方法,然后可以说在这个super-calss中的方法重载了super-class的方法。

什么是方法签名

https://blog.csdn.net/qq_27093465/article/details/54907833

方法签名由方法名称和一个参数列表(方法的参数的顺序和类型)组成。

https://www.thoughtco.com/method-signature-2034235

It's the combination of the method name and the parameter list.

public double calculateAnswer(double wingSpan, int numberOfEngines, double length, double grossTons) 
{ //method code }

you can see that the method signature here is calculateAnswer(double, int, double, double).

这里的方法签名就是 calculateAnswer(double, int, double, double)

什么是形参,什么是实参

https://stackoverflow.com/questions/12709026/difference-between-arguments-and-parameters-in-java

package com.stackoverflow.works; public class ArithmeticOperations { public static int add(int x, int y) { //x, y are parameters(形参) here return x + y;
    } public static void main(String[] args) { int x = 10; int y = 20; int sum = add(x, y); //x, y are arguments(实参) here System.out.println("SUM IS: " +sum);
    }

}

http://www.cs.toronto.edu/~reid/web/javaparams.html

形参: format parameters

实参:actual arguments

    // Method definition public int mult(int x, int y)
    { return x * y;
    } // Where the method mult is used int length = 10; int width = 5; int area = mult(length, width);

x and y are the formal parameters.

length and width are actual parameters.



发表于 2019-02-17 13:22:44 回复(0)
重载与重写(覆写、覆盖)不同 重载必须 方法名相同 参数列表不同(可以是里面参数的类型不同,也可以是参数个数不同,也可以是列表中参数的类型互相换个位置)
发表于 2018-07-14 09:29:37 回复(0)
参数个数和参数类型
发表于 2018-03-31 11:15:36 回复(0)
对比重载是参数类型,办事个数,返回值类型,有一个或多个不同就可以 重写和覆盖是必须全都一致
发表于 2018-03-01 13:07:35 回复(0)
public void method(int i,double j)
{      }
public void method(double j,int i)
{      }
这种也是重载,属于参数列表不同的一种
发表于 2017-11-05 21:37:39 回复(0)