Classes contain methods

Classes contain the code for methods that act on objects; methods have access to the object using the special variable "this".

Here is some code to create a custom Ball class that is used to store information about a ball that will bounce on the screen. The main method of BallExample creates a Ball object using the new keyword and a call to the constructor. Read the code carefully now:

Get hands-on with 1200+ tech skills courses.