Objects - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Objects

Description:

For example an object might be a guest (role), an account (abstract thing), a ... To invoke the behavior, a message is sent to the object reference ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 19
Provided by: Stu87
Category:
Tags: object | objects

less

Transcript and Presenter's Notes

Title: Objects


1
Objects
  • Robert Stumpf, Professor
  • Computer Information Systems
  • California State Polytechnic University Pomona

2
What are Objects
  • Basically they are a collection of data values
    handled as a unit
  • The values are usually of the form of int,
    double, and other data types
  • The values may also be references to other
    objects such as Strings

3
What are Objects
  • A collection of objects are called a class
  • What makes objects special is that behaviors can
    be associated with them
  • These behaviors are implemented as Java methods
  • All objects in a given class have the same methods

4
What are Objects
  • What is good about objects is that they model
    real objects
  • For example an object might be a guest (role), an
    account (abstract thing), a vehicle (real thing),
    a purchase (transaction), or a mouse click (event)

5
What are Objects
  • Note that real objects and model objects both
    have attributes and behavior
  • A model object is an object modeled in Java
  • The attributes are the data values or references
    to other objects
  • The behaviors are the methods

6
What are Objects
  • The fact that an object contains behavior and
    data values is called encapsulation
  • To invoke the behavior, a message is sent to the
    object reference
  • The message must have the same spelling as the
    method name

7
Summary of What Objects Are
  • Objects encapsulate data values and behavior
  • They model real objects
  • They receive messages to invoke their behaviors

8
The Purpose of a Class
  • A class in Java is a mechanism used to define an
    object
  • Sometimes they are called templates for objects
  • They act as a blue print of an object
  • When an object is instantiated (created) the
    template is used

9
The Purpose of a Class
  • Thus in Java the word class is a reserved word
  • In addition there is a visibility modifier for
    each class and members (data and methods) of the
    class
  • For now one chooses private and public

10
The Purpose of a Class
  • A visibility modifier tells the system how to
    protect the members from the outside world (other
    objects)
  • It is recommended to protect the data members,
    thus use private visibility
  • The class and the methods are usually set to
    public visibility which allows them to be used by
    other objects

11
The Purpose of a Class
  • There is one additional feature of classes that
    is often very confusing
  • It is permissible to assign data and behavior to
    the class instead of the object
  • The reserved word static is used to describe
    these class variables and methods
  • The word static means it is the same for all
    objects

12
The Purpose of a Class
  • Examples of static data and methods
  • public static double final Pay_Rate 8.75
  • public static void main(String args)
  • Note that static members are usually public in
    that they are often used by other objects

13
The Purpose of a Class
  • Examples of using static data and methods
  • double root Math.sqrt(x)
  • double pay MyClass.Pay_Rate hours
  • Note that the variables and messages are
    associated with the class name

14
The Purpose of a Class
  • There are some examples which are very confusing
  • For example
  • System.exit(0)
  • The System class is defined in the java.lang
    package and is always available

15
The Purpose of a Class
  • There are some examples which are very confusing
  • For example
  • System.out.println(Hello)
  • The System class has an instance variable called
    out that is instantiated for you
  • Thus println is really an instance method

16
Summary of what Classes are
  • Recall a class is a group of objects classified
    together
  • A class definition is used by the Java system as
    a template to create objects
  • A class may also have data and methods and they
    are called static data and static methods

17
Summary
  • Objects are an important part of the Java
    language
  • They allow us to model real world objects
  • This results in a very meaningful way to program
    in that allows us to create a system to reflect
    the structure of the real world

18
Thank You
  • Java Objects Model Real World Objects
  • Any questions should be directed to Professor
    Robert Stumpf
  • Email rvstumpf_at_csupomona.edu
  • Web Sitehttp//www.csupomona.edu/rvstumpf
Write a Comment
User Comments (0)
About PowerShow.com