150 likes | 164 Views
Learn about objects, classes, attributes, methods, and more in object-oriented programming. Explore how to manipulate object instances and understand the state and behavior of a class.
E N D
Re-Intro to Object Oriented Programming Prof. Elizabeth Adams
What are objects? • Objects are classes • For example, we can have a Car object also known as a Car class • The Car class has attributes or fields that belong to every existing car • For example: • Serial number • Color • Maker • Number of doors
What do you call a particular object? • an instance of the class • Each instance of the class will have all of the attributes of the class
What does a class consist of? State – which is reflected in its attributes Behavior – which is reflected in its actions carried out by its methods
How do you create an instance of a class? You use the new operator
How do you manipulate object instances By calling or invoking methods aka functions or we can pass messages
What do methods consist of? Header (name and a parameter list which MAY be empty) and a body
What are parameters? “stuff” that the methods need to pass additional values into the object instance or content of the messages that are being passed to the object instance
What is the signature of a method? What everyone agrees is part of the signature is the method (function) name, number, type and order of parameters. What others include is the return type. We have been using the 1st definition and calling the 2nd definition the method header
Can you re-use (concurrently) method names? Yes, as long as either the number, type or order of the parameters is different.
What kinds of methods are there? • Constructor – creates a new object instance • Accessor – return information about the state of an object instance • Mutator – changes the state of an object instance
What is state? The “condition” of its attributes
How can you determine state? By using its accessor methods In BlueJ – using the Inspector window
When we talk about attributes of the class, what is the other name we use? Instance variables or fields or properties