Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

AP STUDY SESSION 2.
1
Feichter_DPG-SYKL03_Bild-01. Feichter_DPG-SYKL03_Bild-02.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
Chapter 14 Inheritance. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Inheritance Basics Derived classes, with.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Objectives: Generate and describe sequences. Vocabulary:
UNITED NATIONS Shipment Details Report – January 2006.
7 Copyright © 2005, Oracle. All rights reserved. Creating Classes and Objects.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Create an Application Title 1A - Adult Chapter 3.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 10 second questions
Rhesy S.ppt proRheo GmbH
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Break Time Remaining 10:00.
PP Test Review Sections 6-1 to 6-6
Chapter 17 Linked Lists.
EU market situation for eggs and poultry Management Committee 20 October 2011.
Bright Futures Guidelines Priorities and Screening Tables
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
VOORBLAD.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Adding Up In Chunks.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Chapter 12 OOP: Creating Object- Oriented Programs Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Clock will move after 1 minute
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
1 Chapter 13 Nuclear Magnetic Resonance Spectroscopy.
Copyright © 2012 Pearson Education, Inc. Chapter 14: More About Classes.
Energy Generation in Mitochondria and Chlorplasts
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
User Defined Functions Lesson 1 CS1313 Fall User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough #1.
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
Presentation transcript:

Chapter 9: Using Classes and Objects

Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method – Classes from which you instantiate objects Can contain a Main() method, but it is not required Everything is an object – Every object is a member of a more general class An object is an instantiation of a class Instance variables (also called fields) – Object attributes – Data components of a class 2Microsoft Visual C# 2012, Fifth Edition

Understanding Class Concepts (cont’d.) Instance methods – Methods associated with objects – Every instance of the class has the same methods Class client or class user – A program or class that instantiates objects of another prewritten class 3Microsoft Visual C# 2012, Fifth Edition

Creating a Class from Which Objects Can Be Instantiated Class header or class definition parts – An optional access modifier Default is internal – The keyword class – Any legal identifier for the name of your class Class access modifiers – public – protected – internal – private 4Microsoft Visual C# 2012, Fifth Edition

Creating a Class from Which Objects Can Be Instantiated (cont’d.) 5Microsoft Visual C# 2012, Fifth Edition

Creating Instance Variables and Methods When creating a class, define both its attributes and its methods Field access modifiers – new, public, protected, internal, private, static, readonly, and volatile Most class fields are nonstatic and private – Provides the highest level of security 6Microsoft Visual C# 2012, Fifth Edition

Creating Instance Variables and Methods (cont’d.) Using private fields within classes is an example of information hiding Most class methods are public private data/ public method arrangement – Allows you to control outside access to your data 7Microsoft Visual C# 2012, Fifth Edition

Creating Instance Variables and Methods (cont’d.) 8Microsoft Visual C# 2012, Fifth Edition

Creating Objects Declaring a class does not create any actual objects The two-step process to create an object: – Supply a type and an identifier – Create the object, which allocates memory for it When you create an object, you call its constructor 9Microsoft Visual C# 2012, Fifth Edition

Creating Objects (cont’d.) 10Microsoft Visual C# 2012, Fifth Edition

11Microsoft Visual C# 2012, Fifth Edition Creating Objects (cont’d.)

Passing Objects to Methods You can pass objects to methods just as you can simple data types 12Microsoft Visual C# 2012, Fifth Edition

Passing Objects to Methods (cont’d.) 13Microsoft Visual C# 2012, Fifth Edition

Creating Properties Property – A member of a class that provides access to a field of a class – Defines how fields will be set and retrieved Properties have accessors – set accessors for setting an object’s fields – get accessors for retrieving the stored values Read-only property – Has only a get accessor 14Microsoft Visual C# 2012, Fifth Edition

Creating Properties (cont’d.) 15Microsoft Visual C# 2012, Fifth Edition

Creating Properties (cont’d.) 16Microsoft Visual C# 2012, Fifth Edition

17Microsoft Visual C# 2012, Fifth Edition Creating Properties (cont’d.)

Using Auto-Implemented Properties Auto-implemented property – The property’s implementation is created for you automatically with the assumption that: The set accessor should simply assign a value to the appropriate field The get accessor should simply return the field When you use an auto-implemented property, you do not need to declare the field that corresponds to the property 18Microsoft Visual C# 2012, Fifth Edition

Using Auto-Implemented Properties (cont’d.) 19Microsoft Visual C# 2012, Fifth Edition

Using Auto-Implemented Properties (cont’d.) 20Microsoft Visual C# 2012, Fifth Edition

More About public and private Access Modifiers Occasionally, you need to create public fields or private methods – You can create a public data field when you want all objects of a class to contain the same value const within a class is always static – Belongs to the entire class, not to any particular instance 21Microsoft Visual C# 2012, Fifth Edition

22Microsoft Visual C# 2012, Fifth Edition

More About public and private Access Modifiers (cont’d.) 23Microsoft Visual C# 2012, Fifth Edition

More About public and private Access Modifiers (cont’d.) 24Microsoft Visual C# 2012, Fifth Edition

Understanding the this Reference You might eventually create thousands of objects from a class this reference – An implicitly passed reference When you call a method, you automatically pass the this reference to the method – It tells the method which instance of the class to use 25Microsoft Visual C# 2012, Fifth Edition

Understanding the this Reference (cont’d.) 26Microsoft Visual C# 2012, Fifth Edition

27Microsoft Visual C# 2012, Fifth Edition Understanding the this Reference (cont’d.)

28Microsoft Visual C# 2012, Fifth Edition

Understanding the this Reference (cont’d.) 29Microsoft Visual C# 2012, Fifth Edition

Understanding Constructors Constructor – A method that instantiates an object Default constructor – An automatically supplied constructor without parameters Default value of the object – The value of an object initialized with a default constructor 30Microsoft Visual C# 2012, Fifth Edition

Passing Parameters to Constructors Parameterless constructor – A constructor that takes no arguments 31Microsoft Visual C# 2012, Fifth Edition

Passing Parameters to Constructors (cont’d.) You can create a constructor that receives argument(s) 32Microsoft Visual C# 2012, Fifth Edition

Overloading Constructors C# automatically provides a default constructor until you provide your own constructor Constructors can be overloaded – You can write as many constructors as you want, as long as their argument lists do not cause ambiguity 33Microsoft Visual C# 2012, Fifth Edition

34Microsoft Visual C# 2012, Fifth Edition

Overloading Constructors (cont’d.) 35Microsoft Visual C# 2012, Fifth Edition

Overloading Constructors (cont’d.) 36Microsoft Visual C# 2012, Fifth Edition

Understanding GUI Application Objects Objects you have been using in GUI applications are just like other objects – They encapsulate properties and methods 37Microsoft Visual C# 2012, Fifth Edition

Understanding GUI Application Objects (cont’d.) 38Microsoft Visual C# 2012, Fifth Edition

Understanding GUI Application Objects (cont’d.) 39Microsoft Visual C# 2012, Fifth Edition

Understanding GUI Application Objects (cont’d.) 40Microsoft Visual C# 2012, Fifth Edition