Java中的形式参数是什么? [英] What is a formal parameter, in Java?

查看:322
本文介绍了Java中的形式参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究java遗留代码,我遇到了一个代表正式参数的类,但我不知道为什么会这样。我读到 C ++形式参数的,但它让我感到困惑,因为C ++是一样的作为参数(我对这个肯定有疑问)并且在我的遗留代码中它是一个类,只有一个私有的int成员存储一个数字(带有他们的set& get方法)但老实说,我没有找到的的为什么该声明的。

I'm currently working on java legacy code and I encounter with a class that represent a formal parameter but I don't know why is that. I read about C++ Formal Parameters, but it confused me because in C++ it is the same as the argument (I'm in doubt about this affirmation) and in my legacy code it is a class, that has only a private int member that store a number (with their set & get methods) but honestly, I didn't find the why of that declaration.

推荐答案

在Java和C ++中的形式参数中指定方法的签名:

In Java and in C++ the formal parameter is specified in the signature of the method:

public void callIt(String a)

callIt 有一个正式参数是 String 。在运行时我们讨论实际参数(或参数),:

callIt has a single formal parameter that is a String. At run-time we talk about actual parameters (or arguments), the :

callIt("Hello, World");

Hello,World String 是一个实际参数字符串a 是一个形式参数。

"Hello, World" String is an actual parameter, String a is a formal parameter.

来自维基百科条目参数

术语参数(有时称为形式参数)通常用于引用函数定义中的变量,

The term parameter (sometimes called formal parameter) is often used to refer to the variable as found in the function definition,

和:


参数(有时称为实际参数)是指传递的实际输入。

argument (sometimes called actual parameter) refers to the actual input passed.

这篇关于Java中的形式参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆