DOC PREVIEW
LETU COSC 2103 - Chapter 8 – Object-Based Programming

This preview shows page 1-2-3-4-5-34-35-36-37-38-69-70-71-72-73 out of 73 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 73 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 8 – Object-Based Programming8.1 Introduction8.1 Introduction (cont.)Slide 48.2 Implementing a Time Abstract Data Type with a ClassTime1.java Line 5 Time1 (subclass) extends superclass java.lang.Object Lines 6-8 private variables Lines 12-15 Time1 constructor then invokes method setTime Line 19 public methods Lines 19-24 Method setTime sets private variables according to argumentsTime1.java8.2 Implementing a Time Abstract Data Type with a Class (cont.)TimeTest1.java Line 9 Declare and create instance of class Time1 by calling Time1 constructor Lines 12-26 TimeTest1 interacts with Time1 by calling Time1 public methodsTimeTest1.java8.3 Class Scope8.4 Controlling Access to MembersTimeTest2.java Lines 9-11 Compiler error – TimeTest2 cannot directly access Time1’s private data8.5 Referring to the Current Object’s Members with thisThisTest.javaThisTest.java Lines 31-33 this used to distinguish between argumens and variables Lines 39-40 use explicit and implicit this to call toStandarsString8.6 Initializing Class Objects: Constructors8.7 Using Overloaded ConstructorsTime2.java Lines 12-15 No-argument (default) constructor Line 14 Use this to invoke the Time2 constructor declared at lines 30-33 Lines 18-21 Overloaded constructor has one int argument Lines 24-27 Second overloaded constructor has two int argumentsTime2.java Lines 30-33 Third overloaded constructor has three int arguments Lines 36-40 Fourth overloaded constructor has Time2 argumentTime2.javaTimeTest3.java Lines 9-14 Instantiate each Time2 reference using a different constructorTimeTest3.java8.8 Using Set and Get MethodsTime3.java Lines 6-8 private variables cannot be accessed directly by objects in different classesTime3.java Lines 45-68 Set methods allows objects to manipulate private variablesTime3.java Lines 72-87 Get methods allow objects to read private variablesTime3.javaTimeTest4.java Lines 8 and 17 Declare and instantiate Time3 object Lines 25 and 31 JTextFields allow user to specify hour.TimeTest4.java Line 31 JTextField allows user to specify minute Line 37 JTextField allows user to specify secondTimeTest4.java Lines 71-74 Lines 77-80 Lines 83-86 TimeTest5 uses Time3 set methods to set Time3 private variablesTimeTest4.java Lines 95-96 TimeTest5 uses Time3 get methods to read Time3 private variablesTimeTest4.javaSlide 34Slide 358.9 CompositionDate.java Line 4 Class Date encapsulates data that describes date Lines 11-20 Date constructor instantiates Date object based on specified argumentsDate.javaSlide 39Employee.java Lines 7-8 Employee is composed of two references to Date objectsEmployeeTest.java8.10 Garbage Collection8.11 Static Class MembersEmployee.java Line 6 Employee objects share one instance of count Lines 23-28 Called when Employee is marked for garbage collectionEmployee.java Lines 43-46 static method accesses static variable countEmployeeTest.java Line 12 EmployeeTest can invoke Employee static method, even though Employee has not been instantiatedEmployeeTest.java Line 35 Calls Java’s automatic garbage-collection mechanism8.12 Final Instance VariablesIncrementTest.javaIncrement.java Line 36 final keyword declares INCREMENT as constant Line 41 final variable INCREMENT must be initialized before using itPowerPoint Presentation8.13 Creating PackagesTime1.java Line 3 Class Time1 is placed in this package Line 3 Class Time1 is in directory com/deitel/jhtp5/ch08 Line 5 import class DecimalFormat from package java.textTime1.java Line 31 DecimalFormat from package java.textTimeTest1.java Line 5 import class JOptionPane from package javax.swing Line 8 import class Time1 from package com.deitel.jhtp4.ch08 Line 14 TimeTest1 can declare Time1 objectTimeTest1.java8.14 Package AccessPackageDataTest.java Line 10 Instantiate reference to PackageData object Lines 13-22 PackageDataTest can access PackageData data, because each class shares same packagePackageDataTest.java Line 33 No access modifier, so class has package-access variables8.15 Software Reusability8.16 Data Abstraction and Encapsulation8.16 Data Abstraction and Encapsulation (Cont.)8.17 (Optional Case Study) Thinking About Objects: Starting to Program the Classes for the Elevator Simulation8.17 Thinking About Objects (cont.)Fig 8.19 Class diagram with visibility notations.Slide 66Slide 67Slide 68Slide 698.17 Thinking About Objects (cont.) Step 18.17 Thinking About Objects (cont.) Step 28.17 Thinking About Objects (cont.) Step 38.17 Thinking About Objects (cont.) Step 4 2003 Prentice Hall, Inc. All rights reserved.Chapter 8 – Object-Based ProgrammingOutline8.1 Introduction8.2 Implementing a Time Abstract Data Type with a Class8.3 Class Scope8.4 Controlling Access to Members8.5 Referring to the Current Object’s Members with this 8.6 Initializing Class Objects: Constructors 8.7 Using Overloaded Constructors8.8 Using Set and Get Methods8.9 Composition 8.10 Garbage Collection 8.11 Static Class Members 8.12 Final Instance Variables 8.13 Creating Packages 8.14 Package Access 8.15 Software Reusability 8.16 Data Abstraction and Encapsulation 8.17 (Optional Case Study) Thinking About Objects: Starting to Program the Classes for the Elevator Simulation 2003 Prentice Hall, Inc. All rights reserved.8.1 Introduction•Object Oriented Programming (OOP)–Encapsulates data (attributes) and methods (behaviors)•Objects–Allows objects to communicate•Well-defined interfaces 2003 Prentice Hall, Inc. All rights reserved.8.1 Introduction (cont.)•Procedural programming language–C is an example–Action-oriented–Functions are units of programming•Object-oriented programming language–Java is an example–Object-oriented–Classes are units of programming•Functions, or methods, are encapsulated in classes 2003 Prentice Hall, Inc. All rights reserved.8.1 Introduction (cont.)•This chapter discusses–How to create objects–How to use objects 2003 Prentice Hall, Inc. All rights reserved.8.2 Implementing a Time Abstract Data Type with a Class•We introduce classes Time1 and TimeTest–Time1.java declares class Time1 –TimeTest.java declares class TimeTest–public classes must be declared in separate files–Class Time1 will not execute by itself•Does not have method main•TimeTest, which has method main, creates (instantiates) and uses Time1 object 2003 Prentice Hall, Inc.All rights reserved.OutlineTime1.javaLine 5Time1 (subclass) extends superclass java.lang.Object Lines


View Full Document

LETU COSC 2103 - Chapter 8 – Object-Based Programming

Documents in this Course
Arrays

Arrays

16 pages

Templates

Templates

17 pages

Methods

Methods

22 pages

Methods

Methods

22 pages

Arrays

Arrays

11 pages

Load more
Download Chapter 8 – Object-Based Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 8 – Object-Based Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 8 – Object-Based Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?