Java™ How to Program, 9/e Presented by: Dr. Reyes Álamo © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

Slides:



Advertisements
Similar presentations
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Advertisements

Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Abstract Classes and Interfaces.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Basic OOP Concepts and Terms
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
Java™ How to Program, 9/e Presented by: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Java SE 8 for Programmers, Third Edition Advanced Java Programming.
Object Oriented Programming using Java - Polymorphism
Unit 5 School of Information Systems & Technology1 School of Information Systems and Technology (IST)
Programming Languages and Paradigms Object-Oriented Programming.
COP 3003 Object-Oriented Programming - Polymorphism Dr. Janusz Zalewski, Fall 2013 Prepared by Dr Dahai Guo.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Inheritance.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Lecture 9 Polymorphism Richard Gesick.
Java™ How to Program, 9/e Presented by: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Chapter 8 - Additional Inheritance Concepts and Techniques1 Chapter 8 Additional Inheritance Concepts and Techniques.
Basic OOP Concepts and Terms. In this class, we will cover: Objects and examples of different object types Classes and how they relate to objects Object.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
 2006 Pearson Education, Inc. All rights reserved Polymorphism, Interfaces & Operator Overloading.
 All calls to method toString and earnings are resolved at execution time, based on the type of the object to which currentEmployee refers.  Known as.
Object Oriented Programming.  Interface  Event Handling.
O O P Polymorphism Object Oriented Programming Prepared & Presented by: dr.Ismail Farahat Chapter 4.
Object Oriented Programming
 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Java Software Solutions Lewis and Loftus Chapter 9 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Enhanced Class Design -- Introduction.
Interfaces An interface is like an extreme case of an abstract class – However, an interface is not a class – It is a type that can be satisfied by any.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Object Oriented programming Instructor: Dr. Essam H. Houssein.
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
C++ How to Program, 7/e.  There are cases in which it’s useful to define classes from which you never intend to instantiate any objects.  Such classes.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
A Concrete Presentation on Abstract Classes and Methods, Interfaces, and Polymorphism CSC 202.
Object-Oriented Programming: Polymorphism
Advanced Programming in Java
Sections Inheritance and Abstract Classes
Inheritance and Polymorphism
Object-Oriented Programming: Polymorphism
Interfaces.
Lecture 23 Polymorphism Richard Gesick.
Object-Oriented Programming: Interface
Object-Oriented Programming: Polymorphism
Interface.
Chapter 9 Object-Oriented Programming: Inheritance
Based on slides from Deitel & Associates, Inc.
Advanced Java Topics Chapter 9
Advanced Java Programming
CSE 1030: Implementing GUI Mark Shtern.
Java Inheritance.
Fundaments of Game Design
Abstract Classes and Interfaces
Chapter 14 Abstract Classes and Interfaces
Basic OOP Concepts and Terms
Object-Oriented Programming: Polymorphism
Presentation transcript:

Java™ How to Program, 9/e Presented by: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.

 Interfaces offer a capability requiring that unrelated classes implement a set of common methods.  Interfaces define and standardize the ways in which things such as people and systems can interact with one another.  Example: The controls on a radio serve as an interface between radio users and a radio’s internal components.  Can perform only a limited set of operations (e.g., change the station, adjust the volume, choose between AM and FM)  Different radios may implement the controls in different ways (e.g., using push buttons, dials, voice commands). © Copyright by Pearson Education, Inc. All Rights Reserved.

 The interface specifies what operations a radio must permit users to perform but does not specify how the operations are performed.  A Java interface describes a set of methods that can be called on an object. © Copyright by Pearson Education, Inc. All Rights Reserved.

 An interface declaration begins with the keyword interface and contains only constants and abstract methods.  All interface members must be public.  Interfaces may not specify any implementation details.  All methods declared in an interface are implicitly public abstract methods.  All fields are implicitly public, static and final.  To use an interface, a concrete class must specify that it implements the interface and must declare each method in the interface with specified signature.  Add the implements keyword and the name of the interface to the end of your class declaration.  © Copyright by Pearson Education, Inc. All Rights Reserved.

 An interface is often used when unrelated classes need to share common methods and constants.  Allows objects of unrelated classes to be processed polymorphically by responding to the same method calls.  You can create an interface that describes the desired functionality, then implement this interface in any classes that require that functionality. © Copyright by Pearson Education, Inc. All Rights Reserved.

 An interface is often used in place of an abstract class when there is no default implementation to inherit—that is, no fields and no default method implementations.  Like public abstract classes, interfaces are typically public types.  A public interface must be declared in a file with the same name as the interface and the.java file-name extension. © Copyright by Pearson Education, Inc. All Rights Reserved.

 Next example builds an application that can determine payments for employees and invoices alike.  Classes Invoice and Employee both represent things for which the company must be able to calculate a payment amount.  Both classes implement the Payable interface, so a program can invoke method getPaymentAmount on Invoice objects and Employee objects alike.  Enables the polymorphic processing of Invoice s and Employee s. © Copyright by Pearson Education, Inc. All Rights Reserved.

 Fig shows the accounts payable hierarchy.  A subclass inherits its superclass’s realization relationships. © Copyright by Pearson Education, Inc. All Rights Reserved.

 Fig shows the declaration of interface Payable. © Copyright by Pearson Education, Inc. All Rights Reserved.

 Java does not allow subclasses to inherit from more than one superclass, but it allows a class to inherit from one superclass and implement as many interfaces as it needs.  To implement more than one interface, use a comma- separated list of interface names after keyword implements in the class declaration, as in: public class ClassName extends SuperclassName implements FirstInterface, SecondInterface, … © Copyright by Pearson Education, Inc. All Rights Reserved.

 Check the class OpenLab site for new Labs  Check Blackboard for new Quizzes © by Pearson Education, Inc. All Rights Reserved.