Today I decided to make a top down based game using Java. I have already made the window and included the Jframe. But I found a problem on creating the GameObject in the Rectagle GetBounds(); . I don't know what really is because I am a beginner and I know the basics of java :( .
If anyone can help me to resolve this problem I give the code example below:
package example;
import java.awt.Graphics;
import java.awt.Rectangle;
public abstract class GameObject {
protected int x, y;
protected float velX = 0, velY = 0;
public GameObject(int x, int y) {
this.x = x;
this.y = y;
}
public abstract void tick();
public abstract void render(Graphics g);
public abstract void Rectangle getBounds();
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public float getVelX() {
return velX;
}
public void setVelX(float velX) {
this.velX = velX;
}
public float getVelY() {
return velY;
}
public void setVelY(float velY) {
this.velY = velY;
}
}
The code causes the following errors:
Illegal modifier for the field Rectangle; only public, protected, private, static, final, transient & volatile are permitted Return type for the method is missing Syntax error, insert ";" to complete FieldDeclaration This method requires a body instead of a semicolon void is an invalid type for the variable Rectangle
Note: I'm using Java SE-8 and Eclipse Oxigen.
getBounds()returns aRectangleit should not havevoid. - Loris SecurovoidandRectangleare both return types ofgetBounds. A method can't have multiple return types. - Bernhard Barkerpublic abstract void Rectangle getBounds();should bepublic abstract Rectangle getBounds();- MadProgrammer