Can perform actions and provide communication

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

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.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
Chapter 10 Classes Continued
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
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.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
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.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
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.
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.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Chapter 5 Introduction to Defining Classes
© 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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Object Oriented Programming
© 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.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
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.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
1 More About Derived Classes and Inheritance Chapter 9.
Introduction to Object-oriented Programming
A variable is a name for a value stored in memory.
OOP: Encapsulation &Abstraction
Classes (Part 1) Lecture 3
Chapter 4 Assignment Statement
Chapter 11 Inheritance and Polymorphism
Inheritance and Polymorphism
One class is an extension of another.
Chapter 7 Top-Down Development
Chapter 3: Using Methods, Classes, and Objects
PHP Classes and Objects
Chapter 3 Assignment Statement
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Can perform actions and provide communication
One class is an extension of another.
Object Based Programming
Chapter 9 Inheritance and Polymorphism
Inheritance Basics Programming with Inheritance
Can perform actions and provide communication
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
IFS410: Advanced Analysis and Design
Chapter 3 Classes and Objects
Computer Programming with JAVA
Java Inheritance.
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
CS360 Client/Server Programming Using Java
Chapter 14 Abstract Classes and Interfaces
Inheritance and Polymorphism
Chapter 11 Inheritance and Polymorphism Part 1
Final and Abstract Classes
Chapter 11 Inheritance and Encapsulation and Polymorphism
Chapter 7 Objects and Classes
CSG2H3 Object Oriented Programming
Presentation transcript:

Can perform actions and provide communication 1/11/2019 7:23 AM 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 Refer to page 179 in the text. © 2007 Lawrenceville Press

Used to create, or instantiate, objects 1/11/2019 7:23 AM Chapter 8 Class An abstract data type Used to create, or instantiate, objects Provides encapsulation, also called information hiding Refer to page 179 in the text. © 2007 Lawrenceville Press

Chapter 8 The Circle Class 1/11/2019 7:23 AM Chapter 8 The Circle Class Refer to page 179 in the text. © 2007 Lawrenceville Press

access level class name body variables constructor method Chapter 8 A Class access level class name body public class Circle { private static final double PI = 3.14; private double radius; public Circle() { radius = 1; } public void setRadius(double newRadius) { radius = newRadius; } variables constructor Note: This slide contains animations. Press the space bar or click the mouse button to display each animation. This slide contains six (6) animations. Refer to pages 181 and 182 in the text. A class declaration includes an access level. <press space bar> The keyword public is called an access modifier. A public class is visible to other classes. Class names should be a noun. <press space bar> A class name should begin with an uppercase letter and then an uppercase letter should also begin each word within the name. The body of the class starts with the first opening brace and ends with the matching closing brace. <press space bar> Within the body of a class are the members of the class. The variables of the class are declared first. <press space bar> The visibility of the member variables is controlled with access modifiers. Declaring a variable as private makes it visible to the class, but not to client code. This encapsulates the data and provides and provides information hiding. Variables define the state of an object. A class has at least one constructor. <press space bar> A constructor is automatically called when an object is created. The constructor is where variables are initialized. A class can have several methods. <press space bar> Methods define the behavior of an object. method © 2007 Lawrenceville Press

Chapter 8 Methods in a Class 1/11/2019 7:23 AM 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 Refer to page 182 in the text. © 2007 Lawrenceville Press

Chapter 8 Overloading Constructors 1/11/2019 7:23 AM 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 Refer to page 183 in the text. © 2007 Lawrenceville Press

Chapter 8 Instance and Class Variables 1/11/2019 7:23 AM 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); radius PI Circle spot2 = new Circle(5); radius PI 2 3.14 Refer to page 184 in the text. 5 © 2007 Lawrenceville Press

Chapter 8 Instance and Class Methods 1/11/2019 7:23 AM 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. Refer to pages 184 and 185 in the text. © 2007 Lawrenceville Press

Chapter 8 Differences Between Instance and Class Members 1/11/2019 7:23 AM 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. Refer to pages 184 and 185 in the text. © 2007 Lawrenceville Press

Chapter 8 The Object Class 1/11/2019 7:23 AM 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. Refer to page 185 and 186 in the text. © 2007 Lawrenceville Press

Chapter 8 Classes Using Classes 1/11/2019 7:23 AM 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. Refer to page 187 in the text. © 2007 Lawrenceville Press

Chapter 8 Object-Oriented Development 1/11/2019 7:23 AM 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 Refer to pages 191 through 193 in the text. © 2007 Lawrenceville Press

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. Refer to pages 191 through 193 in the text. © 2007 Lawrenceville Press