Classes and Objects - PowerPoint PPT Presentation

About This Presentation
Title:

Classes and Objects

Description:

Go to your 2nd (Wed or Thurs) lab. Expect something like the programming exercises (P1.1 P1.4) from chapter #1 ... The IMPRESSION is the 'object' DESIGN EXERCISE ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 17
Provided by: thaddeusf
Category:

less

Transcript and Presenter's Notes

Title: Classes and Objects


1
Classes and Objects
  • CSC 171 FALL 2004
  • LECTURE 2

2
LABS
  • Labs start this week.
  • Go to your 2nd (Wed or Thurs) lab
  • Expect something like the programming exercises
    (P1.1 P1.4) from chapter 1
  • You may use notepad and the command prompt

3
History
  • The abacus

4
Questions
  • What is an object?
  • What is a class?
  • What is the difference between an object and a
    class?
  • How do I write a class?
  • How do I make an object?

5
What are objects?
  • Object entity that you can manipulate in your
    programs (by invoking methods)
  • Each object belongs to a class
  • Class Set of objects with the same behavior
  • Class determines legal methods"Hello".println()
    // Error"Hello".length() // OK

6
Classes and Objects
  • Object oriented programs
  • Define classes of objects
  • Make specific object out of class definitions
  • Run by having the objects interact (communicate
    pass messages)
  • A class is a type of thing
  • Instructor
  • An object is a specific thing
  • Ted
  • An object is an instance of a class

7
ANALOGY
  • RUBBER STAMPING
  • The STAMP is the Class definition
  • The IMPRESSION is the object

8
DESIGN EXERCISE
  • Think about the class of things we call
    students
  • What is the data?
  • What are the behaviors?

9
EXAMPLE
(5,10)
  • A rectangle has a location, width, and height

30
20
10
Making an object CONSTRUCTION
  • new Rectangle(5,10,20,30)

11
Reference to an object
  • Rectangle cerealBox new Rectangle(5,10,20,30)

12
Using references
  • System.out.println(The location is (
  • cerealBox.x , cerealBox.y)

13
Multiple references
  • Rectangle cerealBox new Rectangle(5,10,20,30)
  • Rectangle r cerealBox

14
Programming Example
  • The Instructor class
  • Instructors have names

15
Review A Computer Program
  • //Really, A Class definition!
  • public class myFirstProgram
  • public static void main(String args)
  • System.out.println(Hello, CSC171)

16
Questions
  • What is an object?
  • An instance of a class
  • What is a class?
  • A definition of a set of objects
  • What is the difference between an object and a
    class?
  • How do I write a class?
  • With the class pattern
  • How do I make an object?
  • By invoking a constructor
Write a Comment
User Comments (0)
About PowerShow.com