本文介绍了声明函数时初始化vars(Java VS C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是java的新手,我想弄清楚在声明一个函数时是否可以为变量赋值.

这是一些解释 (Correct me if i''m wrong)

在C ++中,我们可以这样写:

Hi all,

I''m new to java and i''m trying to figure out if we could assign values to variables when declaring a function.

Here is some explanation (Correct me if i''m wrong)

in C++ We could write:

class Humain
{
public:
    String nom;
    int age;
public:
    Humain(int age, String name): age(age), name(name){}
}



我想知道我们是否可以像这样用Java编写.

PS:我浏览了许多网站,并且所有网站都使用了以下内容



I''m wondering if we could write in java like that.

PS: i looked in many web sites and all used as below

Humain(int age, String name){
   this.age = age;
   this. name = name;
}



谢谢.



Thank you.

推荐答案


这篇关于声明函数时初始化vars(Java VS C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 16:44
查看更多