SlideServe
Menu
Préférences
© SlideServe · v2026

Objects and Classes: creating simulations

melvin-franks avatar
13 diapositives · 293 Views · Nov 19, 2014

Objects and Classes: creating simulations. Powerpoint created by Beverly McGuire. Objects. Objects are the things that do the action or are acted upon in a simulation. Objects can have data (fields) and behavior (methods).

Objects and Classes: creating simulations - slide 1
01 / 13Objects and Classes: creating simulations
1 / 17

Télécharger la présentation

Objects and Classes: creating simulations
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Objects and Classes: creating simulations Powerpoint created by Beverly McGuire

  2. Objects • Objects are the things that do the action or are acted upon in a simulation. • Objects can have data (fields) and behavior (methods). • Every object is an instance of a class (its classification or type). • The class creates the objects since it knows how big the object needs to be (how many and what type of fields). • All objects keep a reference to the class that created them (they know their type).

  3. What does this mean? • If you go to a restaurant you may be greeted by the greeter and shown to your table. • The waiter will take your order and bring you your food. • The chef will cook the food. If we want to make a simulation of this we will have objects of the type: Greeter, Waiter, Chef, Customer, Order, Food, and so on. • We can have more than one object of each class. • There will usually be several waiters and many customers.

  4. What are Objects used for? • Classes define the data (fields) that objects of that classification will have and the things that they will be able to do (methods). • Classes create objects. Objects act in the simulation.

  5. Analogies: • Job descriptions are like classes. • Workers in those jobs are like the objects. • A class is also like a blueprint or cookie cutter. • Objects are like houses built based on the blueprints or like cookies made with the cookie cutter.

  6. How Create an Object: • You ask the class to create a new object using the new keyword: • new Class(parameterlist) • You can create a new String object by the following: • String name = “Susan";

  7. An Example of Creating an Object: new World(); new Turtle(new World());

  8. Creating a Class: • Classes are defined in files. • Each class is usually defined in its own file. • The file name is the same as the class name with an extension of ".java".

  9. Creating a Class:(cont.) • You define a class using the class keyword: visibility class Name or visibility class Name extends ParentClass • visibility is usually public meaning all other classes can use it

  10. Creating a Class:(cont.) • Name is the name of the class. By convention each word in a class name starts with an uppercase letter like SimpleTurtle. • ParentClass is the name of the class this class inherits from. If a parent class isn't specified the parent is Object.

  11. Creating a Class Common Errors: • Forgetting to declare a variable to hold a reference to a new object • If you create a new object but don't declare a variable to keep track of the reference you won't have any way to refer to it again. The object will be garbage collected and the memory it uses will be released. • new Turtle(new World());

  12. Creating a Class Common Errors: • Not declaring a class in a file with the same name • Don’t try to save out a class into a new file with a different name. The name of the class and the file must match.

  13. Special thanks to Barb Ericson for providing Concept Cards for this presentation