Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

Java
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();		
    }

}
Posted
Updated 19-Aug-16 22:42pm
v2

1 solution

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 variables s and f are not defined in your class.

I suggest you go to Trail: Learning the Java Language (The Java Tutorials)[^] and work through the tutorials.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900