Recall of RandomBall method overriding For another example of method overriding and inheritance look back at the unit 2 class RandomBall , (in version 8 of the bouncing ball world) which overrode the move() method to be random: // RandomBall.java public class RandomBall extends Ball { public RandomBall (int newX, int newY, int newRadius,int newXMotion, int newYMotion) { // call the Ball constructor super( newX, newY, newRadius, newXMotion, newYMotion ); } public void move() { // 50% chance of chaning X motion if( Math.random() > 0.5 ) dx = -dx; // 50% chance of changing Y motion if( Math.random() > 0.5 ) dy = -dy; // move centre of object x = x + dx; y = y + dy; } } // class RandomBall Back to top 
RITSEC - Global Campus Copyright © 1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |