Download presentation
Presentation is loading. Please wait.
Published byJacob Clarke Modified over 9 years ago
1
Object Oriented Programming Lecture 5: BallWorld
2
Jargon Class / Instance Multiple instances of a Class Data fields Methods Class (Static) methods and fields (main) Inheritance (extends), super and sub classes Constructors – order of execution Constructor parameters (overloading)(super) Constants using ‘final’ modifier Accessor routines for fields (information hiding) Responsibilities and Secrets of Classes
3
Demonstration J03 program – Subclassing a Frame object to make BallWorld – Providing a constructor – Overloaded constructors with parameters – Calling the parent (super) class constructor – Creating multiple instances – Overriding ‘paint’ from the Frame class – The Graphics object for drawing J04 program – Having main in the ‘BallWorld’ (J04) class itself
4
Demonstration J05 program again – Making the drawing colour field ‘static’ leads to multiple BallWorld’s having the same drawing colour despite construction
5
Demonstration J06 program – Introduction of Ball class – Use of Rectangle for location – Use of ‘accessor’ routines to set and return fields – Use of ‘final’ fields as constants J06A program (modified in class) – Moving the responsibility from BallWorld to Ball for bouncing the Ball off the wall – Badly done in that the Frame size constants are copied into the Ball class
6
Exercises Chapter 5, page 81-82 (You will need to read the chapter) – Questions 1-10 and 12 Chapter 5, page 82 – Exercises 1-3 – Exercise 4 Required program – is a version of the program developed from Exercise 4 which puts multiple balls into the BallWorld, starting with randomly chosen colours, speeds and directions. This should be verified this week.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.