 2006 Pearson Education, Inc. All rights reserved. 1 4 4 Introduction to Classes and Objects.

Slides:



Advertisements
Similar presentations
Chapter 3 Introduction to Classes, Objects, Methods, and Strings
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
What have we learned so far… Preprocessor directives Introduction to C++ Variable Declaration Display Messages on Screen Get Information from User Performed.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
 2009 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 Pearson Education, Inc. All rights reserved. 3 3 Introduction to Classes and Objects.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter3: Introduction to Classes and Objects 1.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Classes and Objects Systems Programming.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Midterm review Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
 2009 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 01] Introduction to.
Comments are for people Header comments supply basic information about the artifact.
1.  A method describes the internal mechanisms that actually perform its tasks  A class is used to house (among other things) a method ◦ A class that.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Programming - Classes, Objects Methods, Strings 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Java How to Program, Late Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Fall 2012 Lecture 8: File I/O; Introduction to classes.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
Chapter 3 (B) 3.5 – 3.7.  Variables declared in a function definition’s body are known as local variables and can be used only from the line of their.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
計算機程式語言 Lecture 03-1 國立台灣大學生物機電系 林達德 3 3 Introduction to Classes and Objects.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Jozef Goetz,  2014 Pearson Education, Inc. All rights reserved.  2002 Prentice Hall. All rights reserved. expanded by J. Goetz, 2015 credits:
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved. Note: C How to Program, Chapter 16 is a copy of C++ How to Program Chapter.
Chapter 3 Introduction to Classes, Objects and Strings C++ How to Program, 9/e ©2016 by Pearson Education, Inc., Hoboken, NJ. All Rights Reserved. Instructor.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
 2007 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chapter 3 Introduction to Classes, Objects Methods and Strings
3 Introduction to Classes and Objects.
Introduction to Classes and Objects
Chapter 3 Introduction to Classes, Objects and Strings
Yanal Alahmad Java Workshop Yanal Alahmad
Yanal Alahmad Java Workshop Yanal Alahmad
Chapter 3: Using Methods, Classes, and Objects
Dr Shahriar Bijani Winter 2017
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
IFS410: Advanced Analysis and Design
Week 3 Object-based Programming: Classes and Objects
Introduction to Classes and Objects
Introduction to Classes and Objects
Classes, Objects, Methods and Strings
Object Oriented Programming in java
Introduction to Classes and Objects
Classes and Objects Systems Programming.
Introduction to Classes and Objects
Presentation transcript:

 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects

 2006 Pearson Education, Inc. All rights reserved. 2 OBJECTIVES In this chapter you will learn:  What classes, objects, and methods are.  How to declare a class and use it to create an object.  How to implement a class’s behaviors as methods.  How to call an object’s methods to make the methods perform their tasks.

 2006 Pearson Education, Inc. All rights reserved Classes, Objects, Methods, Properties and Instance Variables Class provides one or more methods ─Method represents task in a program ─Describes the mechanisms that actually perform its tasks ─Hides from its user the complex tasks that it performs ─Method call tells method to perform its task Classes contain one or more attributes ─Specified by instance variables ─Carried with the object as it is used

 2006 Pearson Education, Inc. All rights reserved. 4 The method header for DisplayMessage()

 2006 Pearson Education, Inc. All rights reserved Declaring a Class with a Method and Instantiating an Object of a Class Class GradeBook ─Class declarations include: Access modifier ─Keyword public is an access modifier Keyword class Pair of left and right braces ─Method declarations Keyword public indicates method is available to the public Keyword void indicates that there is no return type Access modifier, return type, name of method and parentheses comprise method header ─Naming convention is to capitalize the first letter of every word

 2006 Pearson Education, Inc. All rights reserved. 6 Use class instance creation expression to create object of class GradeBook Call method DisplayMessage using GradeBook object

 2006 Pearson Education, Inc. All rights reserved Declaring a Class with a Method and Instantiating an Object of a Class (Cont.) Class GradeBookTest ─Any class that contains a Main method can be used to execute an application ─ static method is special because it can be called without first creating object of the class ─C# is extensible Programmers can create new classes ─Class instance creation expression Keyword new Then name of class to create and parentheses ─Calling a method Object’s name, then dot separator (. ) Then method’s name and parentheses

 2006 Pearson Education, Inc. All rights reserved Declaring a Method with a Parameter Method parameters ─Additional information passed to a method ─Supplied in the method call with arguments Parameters specified in method’s parameter list ─Part of method header ─Uses a comma-separated list

 2006 Pearson Education, Inc. All rights reserved. 9 Method header DisplayMessage that takes a courseName argument of type string

 2006 Pearson Education, Inc. All rights reserved. 10 Call ReadLine method to read a line of input and assigns it to nameOfCourse Call DisplayMessage with an argument