Hello, I'm trying to write a class Line that forms a line from two points. I have a separate Line main and Point class.
I'm getting errors saying that I need to have a return type for my LineAB method? I'm not sure why, as I mean for it to be a constructor. Do I have a logic error?
I have my other try in comments.
Any help is appreciated, thanks!
Riaan's got your initial problem. You've done one constructor correctly, so it's a bit strange that you thought the second should be different .
Once you've fixed that, it still won't do what you want though. These lines:
define local variables pA and pB, which you assign to. These hide the instance variables pA and pB, which will still be null.
Additionally, why do you have different instance variables p1/p2 and pA/pB? It looks like you only need one pair, and both constructors should initialise that pair. Otherwise you're going to get some very confusing behaviour.
you are trying to create an one more constructor which should be "public Line(int x1, int y1, int x2, int y2)", if a class contains one more constructors, then all of that constructor should be bearing the same name as of the class name. So your class "Line" will contain constructor only with the name "Line"
and so your line of code
is just an another method inside class Line and so it requires a return type like void or int.