Can you tell me how it worked?

Can you tell me how it worked?

public class Ball {

private static final int DIAMETER = 30;
int x = 0;
int y = 0;
int xa = 1;
int ya = 1;
private Game game;

public Ball(Game game) {
    this.game= game;
}

void move() {
    if (x + xa < 0)
        xa = 1;
    if (x + xa > game.getWidth() - DIAMETER)
        xa = -1;
    if (y + ya < 0)
        ya = 1;
    if (y + ya > game.getHeight() - DIAMETER)
        game.gameOver();
    if (collision()){
        ya = -1;
        y = game.racquet.getTopY() - DIAMETER;
    }
    x = x + xa;
    y = y + ya;
}

private boolean collision() {
    return game.racquet.getBounds().intersects(getBounds());
}

public void paint(Graphics2D g) {
    g.fillOval(x, y, DIAMETER, DIAMETER);
}

public Rectangle getBounds() {
    return new Rectangle(x, y, DIAMETER, DIAMETER);
}

}

How is the 'getBounds()' method called into another method 'collision()' without first creating the object of this class - 'Ball'? I mean, it should be like ball.getBounds()

View Answers









Related Tutorials/Questions & Answers:
Can you tell me how it worked?
Can anybody tell me how to resolve this issue?
Advertisements
How can you tell a fake data scientist?
Please tell me how can i convert string to timer
Can anybody tell me how to use #parameters in struts 2 ?
how can i get output pls urget tell me
Can you tell me about Content Management tool -- Intraoven - JSP-Interview Questions
Please tell me how I can access a field (data type char) of resultset in a java class
Please tell me where I can find tutorials on spring hibernate?
Tell me - Struts
Can you help me with applet?
Tell me - Struts
Tell me - Java Beginners
Pls anyboby tell me...
Tell me - Struts
please tell me
plz tell me
tell me coding for this
please tell me
Can you provide me Hibernate configuration tutorial?
please tell me
please tell me
please tell me
please tell me
please tell me
please tell me
please tell me
please tell me
please tell me
ModuleNotFoundError: No module named 'tell-me-your-secrets'
please tell me
please tell me
please tell me
Software graduates please tell me,
Software graduates please tell me,
please tell me
please tell me
please tell me
please tell me
Can you give me Hibernate one to one example?
Can you give me a simple Hibernate Sessionfactory example?
Can you give me some good factory pattern examples?
plzz tell me java code for that diamond
plese tell me the control flow of this program
please tell me the flow of execution of this program
Please tell me the code to generate the below structure
does anybody could tell me who's the author - Struts
please tell me about command line arguments in java?
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
please tell me about command line arguments in java?

Ads