声明用户定义对象的语法错误 [英] Syntax error for declaration of user defined objects
本文介绍了声明用户定义对象的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在java中你必须编写一个构造函数,并且在其中必须使用this关键字并且我开始搞乱这个
什么我试过了:
class add {
// private int q;
// private int z;
public add(){
this .s = 0;
此 .f = 0;
}
public int a( int g, int d){
this .s = g;
此 .f = d;
return g + d;
}
public void main(字符串 [] args){
add d = new add();
}
}
解决方案
这与前一个问题完全相同构造函数中的this问题 [ ^ ]。您正在尝试引用不存在的变量。变量s
和f
未在您的班级中定义。
我建议你去 Trail:学习Java语言(Java教程) [ ^ ]并完成教程。
in java you have to code a constructor and in it "this " keyword has to be used and i am gettin g messed with this
What I have tried:
class add{
// private int q;
// private int z;
public add(){
this.s=0;
this.f=0;
}
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();
}
}
解决方案
This is exactly the same issue as your previous question Problem with "this" in constructor[^]. You are trying to refer to variables that do not exist. The variabless
andf
are not defined in your class.
I suggest you go to Trail: Learning the Java Language (The Java Tutorials)[^] and work through the tutorials.
这篇关于声明用户定义对象的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文