Classes.

Slides:



Advertisements
Similar presentations
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
Advertisements

IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Chapter 3 – Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To.
Chapter 3 Implementing Classes. Instance Variables Instance variables store the data of an object; the fields of an object. Instance of a class: an object.
Object Oriented Design and Classes
Classes. What is a class? Data and the functions (methods) that operate on that data – collectively called members –Example: bank account class Provide.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Function Overloading Having more than one function with the same name. list of argument of a function are called signature of a function. We can have more.
Chapter 9 – Inheritance Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Chapter 2 – An Introduction to Objects and Classes Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Classes. Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, a gradebook.
The Java Programming Language  Simple – but abstract  Safe  Platform-independent ("write once, run anywhere")  Has a Rich growing library  Designed.
Classes. Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, a gradebook.
Object-Oriented Design. Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo.
Object Oriented Programming CSC 171 FALL 2001 LECTURE 11.
Classes. What is a class? Data and the functions (methods) that operate on that data – collectively called members –Example: bank account class Provide.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
1 Classes and Objects Overview l Classes and Objects l Constructors l Implicit Constructors l Overloading methods this keyword l public, private and protected.
Chapter 9: Classes with Instance Variables or Classes=Methods+Variables Asserting Java © Rick Mercer.
Chapter 3 Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand.
Using Objects Object: an entity in your program that you can manipulate Attributes Methods Method: consists of a sequence of instructions that can access.
Object Oriented Design and Classes. What is a class? Programming mechanism to support OOD Data and the methods that operate on that data – collectively.
Chapter 3 Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand.
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.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
Introduction to Object-Oriented Programming
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Chapter 3 Implementing Classes. Assignment Read 3.1 – 3.5 and take notes complete Self Check Exercises 1-10; Due September 24 th Read 3.6 – 3.8 and take.
Classes All Java code must be inside classes Class types – Utility classes Used to store constants, utility methods, etc. – Driver classes – Abstract Data.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
1 Warm-Up Problem Just like with primitive data types (int, double, etc.), we can create arrays of objects. ex: bankAccount employees[100]; Problem: It’s.
1 Introduction to Classes and Objects Chapter 3 Introduction to Classes and Objects Chapter 3.
Session 02 and 03: C# OOP 1 OOP in C#: Classes and Objects in C#. Object-Oriented Design. UML Class Diagram. Object Interaction. FEN AK IT:
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Classes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 3: An Introduction to Classes 1 Chapter 3 An Introduction to Classes.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
OOP in C# - part 1 OOP in C#: –Object Interaction. –Inheritance and Polymorphism (next module). FEN 20121UCN Technology: Computer Science.
Chapter 3 Implementing Classes
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Comp1004: Building Better Objects II Encapsulation and Constructors.
Lecture 3 John Woodward.
Chapter 3 – Implementing Classes
10.2 Classes Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.
Classes Object-oriented programming: Example: Bank transactions
Chapter 3: Using Methods, Classes, and Objects
About the Presentations
Implementing Classes Yonglei Tao.
Lecture 2 of Computer Science II
Packages, Interfaces & Exception Handling
Object-Oriented Programming
Classes In C#.
Chapter Goals To become familiar with the process of implementing classes To be able to implement and test simple methods To understand the purpose and.
Chapter Three - Implementing Classes
Chapter 3 Implementing Classes
Encapsulation and Constructors
Chapter 6 Class Definitions and Member Functions
JAVA CLASSES.
By Rajanikanth B OOP Concepts By Rajanikanth B
Introduction to Object-Oriented Programming
Oriented Design and Abstract Data Type
CSG2H3 Object Oriented Programming
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Classes

Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program Example: a zoo, a gradebook

OOD Goals Robustness Adaptability Reusability Gracefully handle failures Adaptability Evolve as necessary Reusability Many programs use same piece of code

OOD Principles Abstraction Encapsulation Modularity Abstract Data Types (ADTs) Interfaces Encapsulation Information Hiding Modularity Easily plug together components

What is a class? Data and the methods that operate on that data – collectively called members Example: bank account class Provide structure for organizing programs

Methods Typically, data (variables) declared private Methods operate on data accessors – read data, provide access to data but do not change it mutators – change data examples from bank account, zoo??? constructor – builds a new object

Writing Classes Must be implemented in a file named classname.java well…there are also inner classes

BankAccount Class public BankAccount(double balance); public void withdraw(double amount); public void deposit(double amount); public double checkBalance();

Creating and Using Objects BankAccount b = new BankAccount(500); //Type Name = new Type(constructor parameters); //how would you withdraw funds?

Creating and Using Objects //how would you withdraw funds? b.withdraw(300); object_name.method_name(param list);

Constructor Special-case function called when a new object is created Used to initialize member variables Examples? Default constructor takes no parameters

Flight class Think about the design of a class to represent a flight… Data members? Methods?

Exercises Implement and test the Flight class.

Scope What is the scope of each of the variables you declared in your flight class?

static Static class member - a variable with scope the same as a class member 1 per class, not per object Example - car serial number

Exercises Design, implement, and test a Passenger class. Make sure that you keep track of the passenger’s frequent flyer number.