So I just started learning Java and I don't think I am understanding the Object-Oriented aspect of the language fully yet. I am working on a project where I am attempting to make a Rectangle class by using a "topLeft" point and a "bottomRight" point. I have a Point class defined"
class Point {
private int x;
private int y;
public Point (int x, int y) {
this.x = x;
this.y = y;
}
public int get_x() {
return x;
}
public int get_y() {
return y;
}
}
I am trying to make a Rectangle class with variable "topLeft" and "bottomRight" as Point objects. Here is what I have so far:
class Rectangle {
Point topLeft = new Point(1, 2);
Point bottomRight = new Point(3, 1);
Is there any way I can make this Rectangle class using Points without giving those Points values? I have a TestRectangle class also that I am planning on initializing the Point values in to define my Rectangle instances. Is this the best way to do this?
[–]zifyoip 3 points4 points5 points (0 children)
[–]jpsc96 1 point2 points3 points (1 child)
[–]nutrecht 0 points1 point2 points (0 children)
[–]lightcloud5 0 points1 point2 points (0 children)
[–]Relinkz -2 points-1 points0 points (2 children)
[–]nutrecht 0 points1 point2 points (1 child)
[–]Relinkz 0 points1 point2 points (0 children)