Classes & Objects: Examples

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:
Introduction to classes Sangeetha Parthasarathy 06/11/2001.
Based on Java Software Development, 5th Ed. By Lewis &Loftus
C++ Classes & Data Abstraction
Summary of the lecture We discussed –variable scope –instance variable declarations –variable lifetime.
Classes/Objects. Creating Objects Much like creating variables of primitive types –String name; –type name; Object variables hold references, not values.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 8 User-Defined Classes and ADTs. Chapter Objectives Learn about classes Learn about private, protected, public, and static members of a class.
Classes/Objects. Creating Objects Much like creating variables of primitive types –String name; –type name; Object variables hold references, not values.
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.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
A Revamping Of our skills so far. Our Tools so Far Variable - a placeholder for a value Method - a set of code which accomplishes a task Class - a mold.
ECE122 Feb. 22, Any question on Vehicle sample code?
 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.
Classes Definition A class is a data type whose variables are objects Object – a variable that has member functions as well the ability to hold.
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
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.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
© 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.
Object-Based Programming in VB.NET. Must Understand Following: Encapsulation Information hiding Abstract Data Type Class, Instance, Reference Variable.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 7, Feb 6/7, 2013.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
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.
OOP Basics Classes & Methods (c) IDMS/SQL News
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
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#
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
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.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes : Review Java Software Solutions Foundations of Program Design Seventh Edition John.
Procedural and Object-Oriented Programming
Examples of Classes & Objects
Object-Oriented Programming: Classes and Objects
Objects as a programming concept
Review What is an object? What is a class?
CompSci 230 S Programming Techniques
University of Central Florida COP 3330 Object Oriented Programming
Creating Your OwnClasses
Chapter 4: Writing Classes
Object Based Programming
Initializing Arrays char [] cArray3 = {'a', 'b', 'c'};
METHODS AND BEHAVIORS AKEEL AHMED.
Ch 4: Writing Classes Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: Classes and Objects.
Overloading and Overriding
Simple Classes in C# CSCI 293 September 12, 2005.
Variables and Their scope
Chapter 4 Writing Classes.
Chapter 8 Classes User-Defined Classes and ADTs
Outline Anatomy of a Class Encapsulation Anatomy of a Method
CIS 199 Final Review.
NAME 436.
Arrays Arrays are represented by objects but there is no class that array objects are instances of. Variables of array type are declared using bracket.
CSG2H3 Object Oriented Programming
Chapter 5 Classes.
Introduction to Classes and Objects
Presentation transcript:

Classes & Objects: Examples 15 Classes & Objects: Examples

Previously Methods Arguments Return Types Constructors

Review Classes consist of: Instances of classes are called objects Data Variables / members / properties Functionality Methods - which optionally accept arguments and return values Instances of classes are called objects Instance Variables / Methods The default One copy for each instance of the class Class Variables / Methods static One copy shared by all instances of the class

Overview Data Hiding Access Control Class Methods Abstract Classes Understanding Hello World

Data Hiding Class and instance variables can be accessed from anywhere providing the full object or class name is used. Variables declared in a method are “hidden” Local to that method (scope and scoping)

Access Control Methods, classes and variables may be given modifiers to indicate how they may be used. static - used to indicate a class variable public private Public Methods This is the default. Public methods may be used anywhere (providing the full class/object name is used). Private Methods Access is restricted to the class that contains the method.

Class Methods Class methods (like class variables) have the static modifier. This means that they can be used without instantiation. static int squared(int i) { return i*i; } Classes that are not allowed to be instantiated are abstract classes.

Abstract Classes Abstract classes are declared with the abstract modifier. Abstract classes may not be instantiated. Abstract classes serve to hold static variables and methods. This is often useful for libraries of predefined functionality.

Understanding Hello World This class is called Hello The main method is a class method (i.e. it can be accessed without creating an instance of Hello) The main method is public (i.e. accessible outside of the class Hello) The main method does not return any data The Hello class contains a method called main The main method has a parameter called args (an array of String) class Hello { public static void main (String[] args) System.out.println(“Hello World!”); }