Download presentation
Presentation is loading. Please wait.
Published byJune McCoy Modified over 6 years ago
1
Classes and Objects housefly object Insect class mosquito object
The Insect class defines the fields and methods that will exist in all objects that are an instances of the Insect class. The housefly object is an instance of the Insect class. The process of creating a new object is called instantiation. mosquito object The mosquito object is an instance of the Insect class. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
2
Why? Programming simulates real world activities (usually).
The real world is populated by objects, actors who behave in certain ways. Object oriented programming is a natural way to simulate the objects and behaviors in real world activity. (but you can’t take the analogy too far) Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
3
Also why Objects provide a way to encapsulate data and behavior into one package. That package will operate in known ways and then can become part of a larger whole. Look at the java services we have used. They are classes and objects which are “tried and true”. OOP fosters quality code and code reuse. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
4
Object-Oriented Programming
Data (Fields) Methods That Operate on the Data Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
5
Object-Oriented Programming
Object-oriented programming combines data and behavior via encapsulation. Data hiding is the ability of an object to hide data from other objects in the program. Only an object’s methods should be able to directly manipulate its data. Other objects are allowed manipulate an object’s data via the object’s methods. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
6
Object-Oriented Programming
Data (Fields) typically private to this object Methods That Operate on the Data Code Outside the Object Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
7
Object-Oriented Programming Data Hiding
In object-oriented programming, a class “knows itself”. Data is accessed only through well-defined interfaces. These interfaces are the methods. The interfaces protect the data from corruption. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
8
Classes and Instances Many objects can be created from a class.
Each object is independent of the others. String person = “Jenny”; String pet = “Fido”; String favoriteColor = “Blue”; Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
9
Classes and Instances Each instance of the class String contains different data. The instances are all share the same design. Each instance has all of the attributes and methods that were defined in the String class. Classes are defined to represent a single concept or service. Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.