“此”的问题在构造函数中 [英] Problem with "this" in constructor

查看:128
本文介绍了“此”的问题在构造函数中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






错误获取



error getting

class.java:5: error: cannot find symbol
		this.s = g;







class.java:6: error: cannot find symbol
		this.f = d;



i意味着很奇怪它声明在课堂上?对吗?



我尝试了什么:



class Add {

// private int s;

// private int f;

public int a(int g,int d){

this.s = g;

this.f = d;

返回g + d;

}

public void main(String [] args){

add d = new Add();

System.out.print(da(4,5) );

}







}


i mean it weirdly it declaration is in there in class ?? right ?

What I have tried:

class Add{
// private int s;
// private int f;
public int a(int g,int d){
this.s = g;
this.f = d;
return g+d;
}
public void main(String[] args) {
Add d = new Add();
System.out.print(d.a(4,5));
}



}

推荐答案

取消注释类变量s和f(删除前导//)。
Uncomment the class variables s and f (remove the leading //).


这篇关于“此”的问题在构造函数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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