1 Class members Class definitions consist of variable declarations and method definitions, collectively called members of the class. Variables declared.

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:
Spring Semester 2013 Lecture 5
Starting Out with C++, 3 rd Edition 1 Chapter 14 – More About Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14: More About Classes.
Copyright © 2012 Pearson Education, Inc. Chapter 14: More About Classes.
1 Chapter 11 Introducing the Class Pages ( )
Structure.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
CS102--Object Oriented Programming Lecture 17: – Linked Lists Copyright © 2008 Xiaoyan Li.
Where do objects come from? Objects are instances of classes We instantiate classes: –e.g.new chapter1.Terrarium() –There are three parts to this expression:
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
ECE122 L16: Class Relationships April 3, 2007 ECE 122 Engineering Problem Solving with Java Lecture 16 Class Relationships.
Collaboration Diagrams. Example Building Collaboration Diagrams.
Understanding Friends Object-Oriented Programming Using C++ Second Edition 7.
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.
Classes with multiple methods Part 1. Review of classes & objects Early on, we learned that objects are the basic working units in object-oriented programs.
Even More C Programming Pointers. Names and Addresses every variable has a location in memory. This memory location is uniquely determined by a memory.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
UML class diagrams (1) UML = Unified Modeling Language We use only class diagrams, not other UML diagrams Purpose: –keep OO concepts separate from implementation.
Where do objects come from? Objects are instances of classes We instantiate classes: –e.g.new chapter1.Terrarium() –There are three parts to this expression:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
Introduction to Methods
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Chapter 8 - Exponents Multiplication Properties of Exponents.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
An Advanced Code Pattern: Inner Classes CSE301 University of Sunderland Harry R. Erwin, PhD Half Lecture.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14: More About Classes.
Classes, Interfaces and Packages
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
Manipulator example #include int main (void) { double x = ; streamsize prec = cout.precision(); cout
1 Introduction to Object Oriented Programming Chapter 10.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
Lists in Python Lists as Arguments/Parameters. Lists as arguments to functions Just like other data types, lists can be sent to functions as arguments.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Examples of Classes & Objects
FIGURE 4-10 Function Return Statements
Object-Oriented Programming: Classes and Objects
Templates.
Using local variable without initialization is an error.
Buy book Online -
METHODS AND BEHAVIORS AKEEL AHMED.
Chapter 6 Methods: A Deeper Look
Classes & Objects: Examples
Object Oriented Programming (OOP) LAB # 5
Learning Objectives Classes Constructors Principles of OOP
CSE 1030: Implementing GUI Mark Shtern.
Prototype Pattern 1.
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Java Programming Language
ENERGY 211 / CME 211 Lecture 30 December 5, 2008.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
Introduction to Classes and Objects
Presentation transcript:

1 Class members Class definitions consist of variable declarations and method definitions, collectively called members of the class. Variables declared as members of a class are called instance variables, because each instance of the class has its own (private) copy of each instance variable.

Methods accepting information Methods can accept information, via their arguments, in a method call. We have seen this already with the “add” method of the Terrarium: chapter1.Terrarium t = new chapter1.Terrarium(); t.add(new chapter1.Ant()); 2

In this example, the add method is being provided a reference to the newly created Ant object. 3

Methods returning information Methods can return information, as the value of their method call expressions. We have seen this already with the “start” method of the Ant: chapter1.Terrarium t = new chapter1.Terrarium(); t.add(new chapter1.Ant().start()); 4

This example is very similar to the first one, except that the start() method is called on the Ant. What is sent to the add(…) method is the value of the expression new chapter1.Ant().start() The value of this expression is the value returned by the start() method. In this case it is a reference to the Ant object itself. –The only reason we know this is because I know what the start() method does, having written it. 5