i'm learning to create custom classes and can't figure out where I've gone wrong
From main class...
MyPoint p1 = new MyPoint(317, 10);
the error says:
constructor MyPoint in class MyPoint cannot be applied to given types;
required: no arguments
found: int, int
reason: actual and formal argument lists differ in length
this is from my MyPoint class:
private int x, y;
public void MyPoint(int x, int y)
{
this.x = x;
this.y = y;
}
Why isn't MyPoint(317, 10) being fed into the relevant class along with the x and y values?
Any help would be appreciated, thank you.
Constructors don't have return type. This is just a normal method you just made.
Solution: Remove the void
from the method. It should look like
public MyPoint(int x, int y)
{
this.x = x;
this.y = y;
}
remove return type from
public void MyPoint(int x, int y)
constructor cannot have return type not even void
make it
public MyPoint(int x, int y)
{
this.x = x;
this.y = y;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With