I have just started taking Java as a course in college and I am having a problem understanding how to find the syntax errors in a definition for a class.I am not asking for answers I just need help understanding it more.

The class is


public class AA
{

private int x;
private int y;

public void print()
{

System.out.println(x + " " +y);
}
public int sum ()
{
return x + y;

}

public AA ()
{
x = 0;
y = 0;
}

public int AA(int a, int b)
{

x = a;
y = b;

}
}

please help it is very urgent that i understand this.

Are you getting a syntax error? What is the error? We can't help you understand the errors if we don't know what they are.

Please post you code in code tags next time.

Are you trying to overload your constructor logic with public int AA(int a, int b)? If so you do not need the int as this specifies a return type. However, if you are not trying to overload the contstructor you need to return an integer from that method. alternativly change it to void, this may cause errors anyway due to having a method named the same as your class. Let me know the purpose of your final method please.

private variables >> need set and get methods

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.