Properties.

Slides:



Advertisements
Similar presentations
Chapter 4 Constructors and Destructors. Objectives Constructors – introduction and features The zero-argument constructor Parameterized constructors Creating.
Advertisements

Looking inside classes Fields, Constructors & Methods Week 3.
EC-241 Object-Oriented Programming
Static Members, Structures, Enumerations, Generic Classes, Namespaces Learning & Development Team Telerik Software Academy.
Written by: Dr. JJ Shepherd
What have we learned so far… Preprocessor directives Introduction to C++ Variable Declaration Display Messages on Screen Get Information from User Performed.
Lecture 2 Basics of C#. Members of a Class A field is a variable of any type that is declared directly in a class. Fields are members of their containing.
Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)
1. 2 Introduction to Methods  Method Calls  Parameters  Return Type  Method Overloading  Accessor & Mutator Methods  Student Class: Revisited.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
OOP Spring 2006 – Recitation 31 Object Oriented Programming Spring 2006 Recitation 3.
Introduction to Programming with Java, for Beginners Scope.
Lecture From Chapter 6 & /8/10 1 Method of Classes.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
Creating Simple Classes. Outline of Class Account Class Account Account # Balance Holder name phone# Overdrawn (true/false) Data Members Open Credit Debit.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
 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 4 Introduction to Classes, Objects, Methods and strings
Defining Classes I Part A. Class definitions OOP is the dominant programming methodology in use today. OOP is the dominant programming methodology in.
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.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
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.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Creating and Using Class Methods. Definition Class Object.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design.
1 Class and Object Lecture 7. 2 Classes Classes are constructs that define objects of the same type. A Java class uses instance variables to define data.
Non-Static Classes What is the Object of this lecture?
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 7, Feb 6/7, 2013.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Methods.
Module 13: Properties and Indexers. Overview Using Properties Using Indexers.
What About Alice? In Alice, we have seen that we have:  Objects (skater, snowman, snowwoman, camera)  Methods (move, turn, roll, move toward)  Properties.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
C++ Features Function Overloading Default Functions arguments Thinking about objects – relationship to classes Types of member functions Constructor and.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Re-Intro to Object Oriented Programming
Classes (Part 1) Lecture 3
Examples of Classes & Objects
Objects as a programming concept
Creating Your OwnClasses
Anatomy of a class Part I
Method Mark and Lyubo.
Class Inheritance (Cont.)
Defining Classes and Methods
An Introduction to Java – Part II
Classes & Objects: Examples
Classes, Encapsulation, Methods and Constructors (Continued)
The Object-Oriented Thought Process Chapter 04
Java Lesson 36 Mr. Kalmes.
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects – Exercises UTPA – Fall 2012 This set of slides is revised.
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
JAVA CLASSES.
Method of Classes Chapter 7, page 155 Lecture /4/6.
CIS 199 Final Review.
Visual Programming Lecture 4.
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Methods (a.k.a functions)
Anatomy of a class Part I
Day 11 The Last Week!.
Presentation transcript:

Properties

Setting & getting the value of private attribute. C# normally use methods known as set & get methods. These methods (knows aproperties) are made public & private ways to access or modify private data. Declaring Properties <modifier> <type> <property name> { - - - - - - - - - - - - }

Accessors ◆ get accessor. The get accessor is a method used to read values to a property. The get accessor does not take any parameter, but it returns a value of the data type specified in the property declaration statement. In the body of the get accessor, you need to include a return statement. ◆ set accessor. The set accessor is a method used to write values to a property. The set accessor takes a single implicit parameter named value but does not return any value..

public class Car { string color; public string Color1 g e t return color; } s e t color = value;

Car car1 = new Car(); car1.color = “Green”; ◆ read-only property. The property definition of a read-only property contains only the get accessor. ◆ write-only property. The property definition of a write-only property contains only the set accessor. ◆ read-write property. The property definition of a read-write property contains both the get and set accessors.

class Point { int my_X; // my_X is private int my_Y; // my_Y is private public int x get return my_X; } set my_X = value;

public int y { get return my_Y; } set my_Y = value;

class PropApp { public static void Main() Point starting = new Point(); Point ending = new Point(); starting.x = 1; starting.y = 4; ending.x = 10; ending.y = 11; Console.WriteLine("Point 1: ({0},{1})", starting.x, starting.y); Console.WriteLine("Point 2: ({0},{1})", ending.x, ending.y); }