Download presentation
Presentation is loading. Please wait.
1
Objects, Classes, and Methods (PART 1)
Michael M. Pickard, PhD Dept. of Computer Science Stephen F. Austin State Univ.
2
Introduction Fundamental OO Concepts in the Real World
Fundamental OOP Concepts Understanding of some OO Terms
3
Fundamental OO Concepts Related to the Real World
Class - a category of “things” of some kind For example, the “Automobile” class includes a variety of four-wheeled, mechanized vehicles. Object - one of the “things” in a given class For example, a ‘66 GTO is an object belonging to the class of Automobiles.
4
More Fundamental OO Concepts Related to the Real World...
A class can also be thought of as a defining a pattern for creating objects... …so that if one creates something according to the pattern, one has a new object of that class. Example: A 2011 Hyundai Accent
5
OOP Concepts – Class (1) A class can be thought of as the “type” of the objects that are in the class. Think of the Automobile class. A class can also be thought of as a pattern for creating objects.
6
OOP Concepts - Class (2) A class defines the set of data elements (attributes) that are used by the objects, and the set of behaviors (methods) that manipulate the object or interact with related objects.
7
OOP Concepts - Class (3) In other words, a class . . .
can describe data can describe operations on that data (These are called “methods” in Java.)
8
Truisms about Java classes
Every Java source file has a public class; the class name will be the same as the first part of the file name. There can be more than one class defined in a Java source file. Every object belongs to a class. The class describes what its objects are like. Their data (attributes). The actions they can perform (methods).
9
Objects, Classes, and Methods (PaRT 2)
Michael M. Pickard, PhD Dept. of Computer Science Stephen F. Austin State Univ.
10
OOP Concepts – Construction
When we create something according to the definition of a given class, we say we have constructed (or instantiated) a new object in that class. To create a new object, we use a constructor. Example: Scanner keyboard = new Scanner(System.in); Here we have created an object named “keyboard” that is of Scanner type. Now “keyboard” can use any methods defined in the Scanner class.
11
Accessor and Mutator Methods
An accessor (or getter) method simply retrieves data about an object. Example: A mutator (or setter) method changes something about the object.
12
Constructors versus Methods
Constructors have no return type. Names of constructors begin with an uppercase letter. Constructors have the same name as the class whose objects are being built. Constructors are invoked using the new operator.
13
You can build your own classes!
Consider the Dog class . . .
14
You can write a test program!
The test program can test your constructors and methods
15
Summary Fundamental OO Concepts as Related to the Real World
Basic OO Concepts New terms: constructor, mutator, accessor, instance, attribute.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.