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.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
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.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Abstract Classes and Interfaces.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
 2005 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
ISE 582: Web Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 4 JAVA Cup.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
© 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™ 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.
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.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Programming Languages and Paradigms Object-Oriented Programming.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Inheritance in the Java programming language J. W. Rider.
Chapter 8 - Additional Inheritance Concepts and Techniques1 Chapter 8 Additional Inheritance Concepts and Techniques.
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.
 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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Object Oriented Programming
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
 Pearson Education, Inc. All rights reserved Object-Oriented Programming: Polymorphism.
Object Oriented programming Instructor: Dr. Essam H. Houssein.
CET 3640 Instructor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
 2005 Pearson Education, Inc. All rights reserved. 1 Classes and Objects: A Deeper Look.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
An Introduction to Programming with C++ Fifth Edition Chapter 14 Classes and Objects.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Chapter 15 Abstract Classes and Interfaces.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
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.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Polymorphism in Methods
A Concrete Presentation on Abstract Classes and Methods, Interfaces, and Polymorphism CSC 202.
Object-Oriented Programming: Polymorphism
Inheritance and Polymorphism
Interfaces.
Lecture 23 Polymorphism Richard Gesick.
Object-Oriented Programming: Interface
Object-Oriented Programming: Polymorphism
Chapter 9 Object-Oriented Programming: Inheritance
Based on slides from Deitel & Associates, Inc.
Advanced Java Topics Chapter 9
Java Inheritance.
Fundaments of Game Design
Abstract Classes and Interfaces
Object-Oriented Programming: Polymorphism
Chapter 13 Abstract Classes and Interfaces Part 01
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.

 Review topics in the next slides  Absolutely no electronic devices. You bring one you get 0 (zero).  Study, do the quizzes, do the labs, ask questions.

 Java basics  Commands and how they compare to C++ (i.e. if, while, switch, Scanner vs. cin etc.)  What is the Java Virtual Machine (JVM)  Commands to compile and run an application  Java Application Programming Interface (API)  Data Types  Primitive data types  Reference data types  Initial values

 Object-Oriented programming  What is a class  What is an object  Static data and why the main method is static  What are fields  What are methods  What is a constructor  Method overloading  Encapsulation  Inheritance  Polymorphism  Abstract classes  Interfaces