作业帮 > 综合 > 作业

this.age = age

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/05/18 22:33:21
this.age = age
java 语句
this.age = age
this.age是你这个类里的一个变量(实参,分配地址并且储存了的),而后面那个age是形参(通过外来传入的,只在某个method里有效)
举个例子啊:
import java.util.*;
public class example{
public static int age;
public void HowOldAreYou(int yourage){
this.age=yourage;//这就是把yourage赋值给这个类的变量age.
}
public static void main(String[]args){
Scanner s=new Scanner(System.in);
int yourage=s.nextInt();
example e=new example();
e.HowOldAreYou(yourage);
System.out.println(e.age);
}
}
懂了吗?还可以问