Instance methods.

Slides:



Advertisements
Similar presentations
Python Objects and Classes
Advertisements

Overview of Data Structures and Algorithms
C++ Lecture 6 Object Life-times Creating objects using new Using pointers to objects Aggregation (Containment –UML speak) Other C++ class features.
Road Map Introduction to object oriented programming. Classes
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Object Oriented Programming CSC 171 FALL 2001 LECTURE 11.
The Java Keyword this Marie J. Garlitos. Instance Methods First we introduce instance methods: –any method not declared with a static keyword –operates.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
The different kinds of variables in a Java program.
The different types of variables in a Java program.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
BCS 2143 Introduction to Object Oriented and Software Development.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
MSIS 655 Advanced Business Applications Programming Week 1 Introduction to Java
Lecture 12 March 16, The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.
Introduction to Methods. Previously discussed There are similarities in make up of that can help you remember the construct of a class a class in the.
Classes: user-defined types. Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
The Object-Oriented Thought Process Chapter 03
Introduction to Object-oriented Programming
Lecture 3: Introduction to Object and Classes
Objects as a programming concept
Objects as a programming concept
Classes and OOP.
Andy Wang Object Oriented Programming in C++ COP 3330
Object Oriented Programming using Java - Class Instance Variables
Object-Oriented Programming: Classes and Objects
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Lecture 11 B Methods and Data Passing
CSC 113 Tutorial QUIZ I.
Introduction to Data Structures
Introduction To System Analysis and Design PART 2
Classes & Objects: Examples
More Object-Oriented Programming
Object Oriented Programming
Data Structures and Algorithms for Information Processing
Session 2: Introduction to Object Oriented Programming
String.
Workshop for Programming And Systems Management Teachers
Object-Oriented Programming
Defining Classes and Methods
OO Programming Concepts
Unit-2 Objects and Classes
ITE “A” GROUP 2 ENCAPSULATION.
Object Oriented Programming (OOP) Lecture No. 12
C++ Object Oriented 1.
Creating and Using Classes
Chapter 7 Objects and Classes
Presentation transcript:

Instance methods

Method We found that it's more appropriate to put these method inside the BankAccount class

An ideal class The BankAccount class is ideally suited to contain/store: Information about BankAccount ( instance variables) Operations on BankAccount variables ( method) Remember that program = data + algorithm

New notation to invoke a method

Terminology A class method Methods defined with the keyword static An instance method Methods defined without the keyword static

Shadowing a instance variable (1) When the method has: local/parameter variable = class/instance variable The class/instance variable can no longer accessible with the short hand notation in that scope

“This” (1) The Java compiler always assume that the type of the variable this is:

“This” (2) A variable name used inside a method: that matches the name of a local/parameter variable refers to the local/parameter variable Otherwise: it refers to a class variable or an instance variable

Shadowing a instance variable (2) Overcome the shadowing problem with instance variables: Use the full name to access the instance variable:

Object-oriented programming (OOP) An object is an entity with some state information and a set of well-defined operations It can be used to represent something in the real world It can be used to organize information used inside a computer program.

Implementing an object Represent the state information of the object accurately  with (instance) variables,  and Represent the operations on the object accurately  with (instance) methods

Copying an object (1) Both an object and an array are accessed through a reference variable

Copying an object (2)

Copying an object (3)

Copying an object (4)

Classes with private variables (1) Security/correctness considerations in computer programming

Classes with private variables (2) If there exist complex relationships between different  instance variables, we must maintain the relationship correctly Granting unrestricted access to the instance variables can result in incorrect changes and can give result in data inconsistency

Classes with private variables (3) public = there are no access restrictions to a variable or  method

Classes with private variables (4) private = access is restricted to the same class

Classes with private variables (5)