Reputation: 70
I am getting following error. Please help
Error: method does not override or implement a method from a supertype
class Point2D {
double x;
double y;
public double getX() {
return x;
}
public double getY() {
return y;
}
public Point2D(double x, double y) {
this.x = x;
this.y = y;
}
public double dist2D(Point2D p) {
x = (int) Math.ceil(Math.sqrt(Math.pow((p.getX() - x), 2) + Math.pow((p.getY() - y), 2)));
return x;
}
public static void printDistance(Double d) {
System.out.println("2D distance =" + d);
}
}
class Point3D extends Point2D {
double z;
public double getZ() {
return z;
}
@Override
public static void printDistance(Double d) {
System.out.println("3D distance =" + d);
}
public Point3D(double x, double y, double z) {
super(x, y);
this.z = z;
}
public double dist3D(Point3D p) {
return Math.ceil(Math.sqrt(Math.pow((p.getX() - x), 2) + Math.pow((p.getY() - y), 2) + +Math.pow((p.getZ() - z), 2)));
}
}
public class Solution {
public static void main(String[] args) {
Point3D p1 = new Point3D(1, 2, 3);
Point3D p2 = new Point3D(4, 5, 6);
double d2 = p1.dist2D(p2);
double d3 = p1.dist3D(p2);
Point2D p = new Point2D(0, 0);
p.printDistance(d2);
p = p1;
p.printDistance(d3);
}
}
Expected Output:
2D distance = 5
3D distance = 6
Error: method does not override or implement a method from a supertype
Let me know for additional info
Upvotes: 2
Views: 155
Reputation: 400
Static method cannot be overridden, though they can be overloaded. If you remove the annotation @Override and call the method with class Point3D the code will work.
Upvotes: 3