Welcome back to Software Development!

Slides:



Advertisements
Similar presentations
1 Inheritance Classes and Subclasses Or Extending a Class.
Advertisements

1.00 Lecture 11 Scope and Access. Variable Lifecycles Instance (or object) variables – Created when their containing object is created – Initialized to.
Local Variables and Scope Benjamin Fein. Variable Scope A variable’s scope consists of all code blocks in which it is visible. A variable is considered.
Summary of the lecture We discussed –variable scope –instance variable declarations –variable lifetime.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 13P. 1Winter Quarter Scope of Variables.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Introduction to Programming with Java, for Beginners Scope.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Lecture From Chapter 6 & /8/10 1 Method of Classes.
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
CSC 212 Object-Oriented Programming and Java Part 1.
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.
A class in Java is a software construct that includes fields (also called data fields or class scope variables) to provide data specification, and methods.
Recitation 2 James Wei Professor Peck 1/17/2013. Covered in this Recitation Arrays Variable Scoping Local variables Instance variables Class variables.
CSC 142 D 1 CSC 142 Instance methods [Reading: chapter 4]
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
1. 2  Classes are not just containers for methods ◦ Virtually all are classes ◦ Blueprint/Cookie Cutter/Recipe ◦ Objects – instance of the class (new)
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
CITA 342 Section 1 Object Oriented Programming (OOP)
Classes, Interfaces and Packages
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
C++ Namespaces, Exceptions CSci 588: Data Structures, Algorithms and Software Design All material not from online sources copyright © Travis Desell, 2011.
Advanced Java class Nested Classes & Interfaces. Types of Nested Classes & Interfaces top-level nested –classes –interfaces inner classes –member –local.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
Functions + Overloading + Scope
Name Spaces: ALL versus OOL
Classes and Objects.
Object-Oriented Programming: Classes and Objects
Encapsulation, Data Hiding and Static Data Members
Chapter 5 Classes.
PHP Classes and Objects
OpenMP Quiz B. Wilkinson January 22, 2016.
Lecture 14 Writing Classes part 2 Richard Gesick.
Object-Oriented Programming: Classes and Objects
Object-Oriented Programming Using C++
Using local variable without initialization is an error.
Interfaces and Inner Classes
Classes & Objects: Examples
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Variables and Their scope
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises UTPA – Fall 2012 This set of slides is revised from.
Welcome back to Software Development!
The University of Texas – Pan American
Welcome back to Software Development!
The lifespan of a variable
Anatomy of a Java Program
Object-Oriented Programming Using C++
OpenMP Quiz.
Welcome back to Software Development!
CIS 199 Final Review.
Welcome back to Software Development!
Object Oriented Programming
Welcome back to Software Development!
Classes and Objects Imran Rashid CTO at ManiWeber Technologies.
This is my sheet And this is my sheet.
Chapter 5 Classes.
Presentation transcript:

Welcome back to Software Development!

Reading Questions

Reading Questions What are scope modifiers (public/private)

Reading Questions What are scope modifiers (public/private) What are properties (Set/Get)?

Reading Questions What are scope modifiers (public/private) What are properties (Set/Get)? What is an instance (static and new)?

Reading Questions What are scope modifiers (public/private) What are properties (Set/Get)? What is an instance (static and new)? What are instance variables?

Reading Questions What are scope modifiers (public/private) What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters?

Reading Questions What are scope modifiers (public/private) What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters?

Reading Questions What are scope modifiers (public/private) What are properties (Set/Get)? What is an instance (static and new)? What are instance variables? What are filters?

Review – Class Members

Review – Class Members Methods

Review – Class Members Methods – class algorithms

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’

Review – Class Members Methods – class algorithms Fields The actual code that does the work – the ‘algorithm’ Fields

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use What the book calls “instance variables”

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use What the book calls “instance variables” The data or information the class uses to do its job

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use What the book calls “instance variables” The data or information the class uses to do its job Properties

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use What the book calls “instance variables” The data or information the class uses to do its job Properties – “smart fields”

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use What the book calls “instance variables” The data or information the class uses to do its job Properties – “smart fields” Methods that look like fields…you can use them almost like variables

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use What the book calls “instance variables” The data or information the class uses to do its job Properties – “smart fields” Methods that look like fields…you can use them almost like variables They “protect” the class variables (fields)

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use What the book calls “instance variables” The data or information the class uses to do its job Properties – “smart fields” Methods that look like fields…you can use them almost like variables They “protect” the class variables (fields)

Review – Class Members Methods – class algorithms The actual code that does the work – the ‘algorithm’ Fields – class variables any method of the class can use What the book calls “instance variables” The data or information the class uses to do its job Properties – “smart fields” Methods that look like fields…you can use them almost like variables They “protect” the class variables (fields)

Scope Exercise

Scope Exercise Follow directions on the sheet

Scope Exercise Follow directions on the sheet You will get a compiler error

Scope Exercise Follow directions on the sheet You will get a compiler error There should only be one!

Scope Exercise Follow directions on the sheet You will get a compiler error There should only be one! It will be about the name ‘b’

Scope Exercise Follow directions on the sheet You will get a compiler error There should only be one! It will be about the name ‘b’ If you get something else, you typed the code in wrong

Scope Exercise Follow directions on the sheet You will get a compiler error There should only be one! It will be about the name ‘b’ If you get something else, you typed the code in wrong You have about 10 minutes…

Scope

Scope ‘Scope’ means the section of code a variable can be used in

Scope ‘Scope’ means the section of code a variable can be used in Defined by the current block

Scope ‘Scope’ means the section of code a variable can be used in Defined by the current block Blocks are marked by the immediate surrounding curly braces

Scope ‘Scope’ means the section of code a variable can be used in Defined by the current block Blocks are marked by the immediate surrounding curly braces Includes all inner blocks

Scope ‘Scope’ means the section of code a variable can be used in Defined by the current block Blocks are marked by the immediate surrounding curly braces Includes all inner blocks Question:

Scope ‘Scope’ means the section of code a variable can be used in Defined by the current block Blocks are marked by the immediate surrounding curly braces Includes all inner blocks Question: Can one method use a variable declared in another method?

Scope ‘Scope’ means the section of code a variable can be used in Defined by the current block Blocks are marked by the immediate surrounding curly braces Includes all inner blocks Question: Can one method use a variable declared in another method? No

Scope ‘Scope’ means the section of code a variable can be used in Defined by the current block Blocks are marked by the immediate surrounding curly braces Includes all inner blocks Question: Can one method use a variable declared in another method? No If we needed to be able to do this, how could we do it?

Scope ‘Scope’ means the section of code a variable can be used in Defined by the current block Blocks are marked by the immediate surrounding curly braces Includes all inner blocks Question: Can one method use a variable declared in another method? No If we needed to be able to do this, how could we do it? Fields

Scope Modifiers

Scope Modifiers public / private

Scope Modifiers public / private public:

Scope Modifiers public / private public: Info anyone can get to

Scope Modifiers public / private public: Info anyone can get to My name…

Scope Modifiers public / private public: private: Info anyone can get to My name… private:

Scope Modifiers public / private public: private: Info anyone can get to My name… private: “PB”… Private Business

Scope Modifiers public / private public: private: Info anyone can get to My name… private: “PB”… Private Business Info only select people can get to

Scope Modifiers public / private public: private: Info anyone can get to My name… private: “PB”… Private Business Info only select people can get to My social security number…

Scope Modifiers

Scope Modifiers They are now called access modifiers

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class.

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class. public:

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class. public: Any code with access to the class can read or change a public field!

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class. public: Any code with access to the class can read or change a public field! Very dangerous - rarely use this.

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class. public: Any code with access to the class can read or change a public field! Very dangerous - rarely use this. private:

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class. public: Any code with access to the class can read or change a public field! Very dangerous - rarely use this. private: Only members of the same class can read or change a private field. Example…

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class. public: Any code with access to the class can read or change a public field! Very dangerous - rarely use this. private: Only members of the same class can read or change a private field. If we shouldn’t use public, how to we safely let other code access our fields?

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class. public: Any code with access to the class can read or change a public field! Very dangerous - rarely use this. private: Only members of the same class can read or change a private field. If we shouldn’t use public, how to we safely let other code access our fields? Properties

Scope Modifiers They are now called access modifiers They control who can “access” the fields of a class. public: Any code with access to the class can read or change a public field! Very dangerous - rarely use this. private: Only members of the same class can read or change a private field. If we shouldn’t use public, how to we safely let other code access our fields? Properties – “smart fields” that control reading (Get) and changing (Set)