METHODS AND BEHAVIORS AKEEL AHMED.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
1 Chapter Three Using Methods. 2 Objectives Learn how to write methods with no arguments and no return value Learn about implementation hiding and how.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Chapter 14: Overloading and Templates
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
VBA Modules, Functions, Variables, and Constants
C# Programming: From Problem Analysis to Program Design1 Arrays C# Programming: From Problem Analysis to Program Design 3 rd Edition 7.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Learners Support Publications Classes and Objects.
1 SystemVerilog Enhancement Requests Daniel Schostak Principal Engineer February 26 th 2010.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
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.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Classes: user-defined types. Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
© 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.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
An Introduction to Programming with C++ Sixth Edition Chapter 10 Void Functions.
Introduction to Object-Oriented Programming Lesson 2.
Chapter 8: Advanced Method Concepts. Understanding Parameter Types Mandatory parameter – An argument for it is required in every method call Four types.
BIL528 – Bilgisayar Programlama II Methods 1. Contents Methods 2.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Classes - Part II (revisited) n Constant objects and member functions n Definition Form of Member Functions n friend functions and friend classes n Constructors.
The const Keyword Extreme Encapsulation. Humble Beginnings There are often cases in coding where it is helpful to use a const variable in a method or.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
What is an object?. What Makes an Object? An object has identity (it acts as a single whole). Every object has a name that identifies what it is. Ex.
User-Written Functions
Programming Logic and Design Seventh Edition
Chapter 7: User-Defined Functions II
Examples of Classes & Objects
Object-Oriented Programming: Classes and Objects
Java Programming: Guided Learning with Early Objects
Chapter 10: Void Functions
Chapter 7 Top-Down Development
Chapter 3: Using Methods, Classes, and Objects
Function There are two types of Function User Defined Function
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
Creating Your OwnClasses
Object-Oriented Programming: Classes and Objects
Object Based Programming
Heterogeneous aggregate datatypes
Corresponds with Chapter 7
Classes & Objects: Examples
Classes and Objects.
Defining Classes and Methods
Static is one of the modifiers that determine variable and method characteristics. The static modifier associates a variable or method with its class.
Lecture 5: Functions and Parameters
C# Programming: From Problem Analysis to Program Design
C Parameter Passing.
Presentation transcript:

METHODS AND BEHAVIORS AKEEL AHMED

Overview Anatomy of a Method Modifiers Writing Your Own Class Methods Types of Parameters Named and Optional Parameters

Anatomy of a Method A method is really nothing more than a group of statements placed together under a single name. Methods are defined inside a class. Methods are the members of a class that perform an action. Through writing methods you describe the behavior of data. Methods are similar to functions, procedures, and modules found in other programming languages. Main( ) is a method you have already written as the entry point into your program

Anatomy of a Method

Modifiers A modifier is added to a type or a type member’s declaration to change or alter it or to indicate how it can be accessed. Previously you learned about and used the const modifier const is added to a declaration to indicate that a value is constant and cannot be changed

STATIC MODIFIER All Main( ) method headings must include the static modifier. Static is used in this context to indicate that a method belongs to the type itself rather than to a specific object of a class. Methods that use the static modifier are called class methods. A single copy of the method is made instead of copies for each object. Instance methods require that an object be instantiated before the method is accessed

ACCESS MODIFIERS Another type of modifier is an access modifier. It specifies the level of accessibility for types and their members C# includes the following accessibility modifiers:

Writing Your Own Class Methods

Types of Parameters C# offers both call by value and call by reference parameters. Call by Value: With call by value, a copy of the original value is made and stored in a separate, different memory location. If the method changes the contents of the variable sent to it, this does not affect the original value stored in the variable from the calling method. There are three other types of parameters available in C#: Ref out params

params , ref and out The params type facilitates sending a varying number of arguments into a method. When you use the keywords ref and out, call by reference is assumed. With call by reference, you send the address of the argument to the method The keywords differ in that the ref keyword cannot be used unless the original argument is initialized before it is sent to the method. This restriction does not exist for out. The out keyword is useful for methods that allow users to enter the variable’s value in a method, and have those values available back in the calling method when control returns.