I'm new to Java and OOP, I have one super-class and one sub-class like above. When I try to inherit the methods of super-class inside the sub-class and compile the code, it gives me a @782a9122 result. Where am I wrong??
thanks for your helps.
class A {
// to inherit from normal class => use `extends` keyword
// to inherit from interface class => use `implements` keyword
private int _x, _y;
public A(int x, int y) {
this._x = x;
this._y = y;
}
public int getX() {return _x;}
public int getY() {return _y;}
public void move(int x, int y) {
this._x = x;
this._y = y;
}
}
class B extends A {
private String _color;
public B(int x, int y, String color) {
super(x, y);
this._color = color;
}
// i try to invoke the method of super-class inside the sub-class
public void setXY(int x, int y) {
super.move(x, y);
}
public void setColor(String color) {
this._color = color;
}
public static void main(String[] args) {
B b = new B(5, 5, "Yellow");
// when I compile this code, I got the@4759e894 as the result.
b.setXY(10, 20);
b.setColor("Red");
String str = b.toString();
System.out.println(str);
}
}