© 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.

Slides:



Advertisements
Similar presentations
Reusable Classes.  Motivation: Write less code!
Advertisements

1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
1 Chapter 7 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Object Oriented Concepts in Java Objects Inheritance Encapsulation Polymorphism.
Object-oriented Programming Concepts
Chapter 10 Classes Continued
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
© 2007 Lawrenceville Press Slide 1 Chapter 7 Top-Down Development  Problem-solving approach  Breaking a task down into smaller subtasks  First level.
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
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.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
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.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Classes Java and other Object-Orientated Programs or OOP are based on the creation and interaction of classes. Every program in Java has at least one class.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Coming up: Inheritance
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
Classes and Object- Oriented Development Chapter 8.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
1 More About Derived Classes and Inheritance Chapter 9.
OOP: Encapsulation &Abstraction
Inheritance and Polymorphism
One class is an extension of another.
Can perform actions and provide communication
One class is an extension of another.
Can perform actions and provide communication
Inheritance, Polymorphism, and Interfaces. Oh My
Classes & Objects: Examples
Can perform actions and provide communication
Java Inheritance.
Inheritance and Polymorphism
CIS 199 Final Review.
Chapter 11 Inheritance and Encapsulation and Polymorphism
Presentation transcript:

© 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 perform actions and provide communication  State of object refers to the data it stores  Behavior of object refers to the action and communication it provides

© 2007 Lawrenceville Press Slide 2 Chapter 8 Class  An abstract data type  Used to create, or instantiate, objects  Provides encapsulation, also called information hiding

© 2007 Lawrenceville Press Slide 3 Chapter 8 The Circle Class

© 2007 Lawrenceville Press Slide 4 Chapter 8 A Class public class Circle { private static final double PI = 3.14; private double radius; public Circle() { radius = 1; } public void setRadius(double newRadius) { radius = newRadius; } access level class name body variables constructor method

© 2007 Lawrenceville Press Slide 5 Chapter 8 Methods in a Class  An accessor method is used to determine the value of a variable  A modifier method is used to change the value of a variable  A helper method is called from within a class by other methods

© 2007 Lawrenceville Press Slide 6 Chapter 8 Overloading Constructors  Constructors can be overloaded to provide more options for instantiating an object  The compiler uses the number and types of parameters to determine which constructor to execute

© 2007 Lawrenceville Press Slide 7 Chapter 8 Instance and Class Variables  Each object of a class has its own copy of the instance variables in the class.  A class variable is declared with the keyword static and only one copy of a class variable is maintained for all objects to refer to. Circle spot1 = new Circle(2);radiusPI Circle spot2 = new Circle(5);radiusPI

© 2007 Lawrenceville Press Slide 8 Chapter 8 Instance and Class Methods  Instance methods must be called from an instance of the class. Accessor and modifier methods are always instance methods because they change the state of an object.  Class methods are declared using the keyword static and can be called from the class itself.

© 2007 Lawrenceville Press Slide 9 Chapter 8 Differences Between Instance and Class Members  Instance variables are created each time an object is declared.  Class variables are created once for the class and then objects of the class refer to this copy.  Instance methods can only be called from an object of the class.  Class methods can be called from the class itself.

© 2007 Lawrenceville Press Slide 10 Chapter 8 The Object Class  Superclass of all other classes. Classes, such as Circle and String, are subclasses:  All subclasses inherit the Object methods, which include equals() and toString().  Inherited superclass methods can be redefined, or overridden, in subclasses.

© 2007 Lawrenceville Press Slide 11 Chapter 8 Classes Using Classes  A class containing a member variable that is a class data type.  Demonstrates a has-a relationship. The class "has-a" class.

© 2007 Lawrenceville Press Slide 12 Chapter 8 Object-Oriented Development  Objects are selected to model a program specification  Objects are created from new classes or from existing classes  Objects send messages to other objects to perform a task

© 2007 Lawrenceville Press Slide 13 Chapter 8 Features of Object-Oriented Programming  Reusability: existing classes can be used over and over again in different applications, which reduces development time and decreases the likelihood of bugs.  Modular: Components are separately written and maintained.