Presentation is loading. Please wait.

Presentation is loading. Please wait.

Classes and Objects CSC 171 FALL 2004 LECTURE 2. LABS Labs start this week. Go to your 2 nd (Wed or Thurs) lab Expect something like the programming exercises.

Similar presentations


Presentation on theme: "Classes and Objects CSC 171 FALL 2004 LECTURE 2. LABS Labs start this week. Go to your 2 nd (Wed or Thurs) lab Expect something like the programming exercises."— Presentation transcript:

1 Classes and Objects CSC 171 FALL 2004 LECTURE 2

2 LABS Labs start this week. Go to your 2 nd (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 A rectangle has a location, width, and height (5,10) 20 30

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


Download ppt "Classes and Objects CSC 171 FALL 2004 LECTURE 2. LABS Labs start this week. Go to your 2 nd (Wed or Thurs) lab Expect something like the programming exercises."

Similar presentations


Ads by Google