©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

PHP functions What are Functions? A function structure:
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
©2004 Brooks/Cole Chapter 7 Strings and Characters.
©Brooks/Cole, 2001 Chapter 9 Pointers. ©Brooks/Cole, 2001 Figure 9-1.
Summary of the lecture We discussed –variable scope –instance variable declarations –variable lifetime.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
©2004 Brooks/Cole Chapter 6 Methods. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Using Methods We've already seen examples of using methods.
©Brooks/Cole, 2001 Chapter 9 Pointers. ©Brooks/Cole, 2001 Figure 9-1.
©Brooks/Cole, 2001 Chapter 2 Introduction to The C Language.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
©Brooks/Cole, 2001 Chapter 8 Arrays. ©Brooks/Cole, 2001 Figure 8-1.
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
©Brooks/Cole, 2001 Chapter 7 Text Files. ©Brooks/Cole, 2001 Figure 7-1.
©Brooks/Cole, 2001 Chapter 3 Structure of a C Program.
©Brooks/Cole, 2001 Chapter 10 Pointer Applications.
©Brooks/Cole, 2001 Chapter 11 Strings. ©Brooks/Cole, 2001 Figure 11-1.
Reference … and Misc Other Topics Clark Savage Turner, J.D., Ph.D. Some lecture slides have been adapted from those developed.
©Brooks/Cole, 2001 Chapter 4 Functions. ©Brooks/Cole, 2001 Figure 4-1.
©2004 Brooks/Cole Chapter 6 Methods and Scope. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 A Method Can Be Viewed as a Black Box To use a.
Introduction to Java Programming, 4E Y. Daniel Liang.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
CSE 1302 Lecture 7 Object Oriented Programming Review Richard Gesick.
Lecture # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
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.
Dale Roberts CSCI 230 Functions Scope, Parameter Passing, Storage Specifiers Department of Computer and Information Science, School of Science, IUPUI Dale.
Classes: user-defined types. Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner.
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.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
ECE 103 Engineering Programming Chapter 31 C Scopes Herbert G. Mayer, PSU CS Status 8/1/2015 Initial content copied verbatim from ECE 103 material developed.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Java for Engineers and Scientists 1 st Edition Gary J. Bronson.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Starting Out With Java Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved. Chapter 9 Slide #1 Review.
1 Chapter 8 Scope, Lifetime, and More on Functions CS185/09 - Introduction to Programming Caldwell College.
CLASSES IN JAVA Primitive Types Example of a Class Allocating Objects of a Class Protecting Class data Constructors Static data and Static Methods.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
Examples of Classes & Objects
Haidong Xue Summer 2011, at GSU
Java Programming: Guided Learning with Early Objects
Chapter 8 Classes and Objects
Using local variable without initialization is an error.
More Object Oriented Programming
Can perform actions and provide communication
Object Oriented Programming
Scope, Parameter Passing, Storage Specifiers
METHODS AND BEHAVIORS AKEEL AHMED.
Classes & Objects: Examples
Variables and Their scope
CHAPTER 6 GENERAL-PURPOSE METHODS
CS100J Lecture 8 Previous Lecture This Lecture Programming Concepts
Objects and Classes Creating Objects and Object Reference Variables
Object Oriented Programming Review
Chapter 6 Objects and Classes
Class Circle { Float xc, yc, radius;
SPL – PS3 C++ Classes.
Presentation transcript:

©2004 Brooks/Cole Chapter 10 More on Classes

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting one variable equal to another copies the value of the variable on the right into the variable on the left. With objects, what is copied is the address of the object –there is only one object

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Two Book objects After Assignment book2 = book1

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Making Copies of Objects To copy an object you need a method –Copy constructor public Date( Date original) –A method public void setEqual( Date d) –Override the clone method from the Object class

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Scope Re-visited Variables declared inside a method are local to the method Method parameters are local to the method Variables declared in the body of a class (outside on any method) are visible in all the methods of the class

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 An Example of Scopes

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Static Members Variables declared with the static modifier are shared by all objects that belong to the class Methods declared with a static modifier do not have any instance data associated with them

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sharing the Static Data Member taxRate

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 The Storage of Two Date Objects in Memory