Www.javacup.ir Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
UML Class Diagram: class Rectangle
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.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
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.
Object-oriented programming: C++ class A { private: …… // can be accessd by A protected: …… // can be accessed by A and // its derived classes public:
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
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.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 10 - Interfaces.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Object-Oriented Programming Chapter Chapter
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Interfaces Are used to model weak inheritance relationships Object-inheritance.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
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.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Programming in Java: lecture 7
A Concrete Presentation on Abstract Classes and Methods, Interfaces, and Polymorphism CSC 202.
Advanced Programming in Java
Advanced Programming in Java
Sections Inheritance and Abstract Classes
UML Class Diagram: class Rectangle
CS240: Advanced Programming Concepts
Inheritance, Polymorphism, and Interfaces. Oh My
Interfaces.
Advanced Programming in Java
Java Inheritance.
Advanced Programming in Java
Chapter 14 Abstract Classes and Interfaces
Presentation transcript:

Sadegh Aliakbary

Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP is clearly noted as the source in the used case. JAVACUP shall not be liable for any errors in the content, or for any actions taken in reliance thereon. Please send your feedback to 2JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Agenda interface Multiple Inheritance 3JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Abstract Example 4JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Abstract Method All subclasses have the method But we can not implement the method in super-class So why we define it in super-class? Polymorphism 5JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Interface Sometimes we have an abstract class, with no concrete method interface : pure abstract class no implemented method 6JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Interface 7JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Interface All the methods are implicitly abstract No need to abstract specifier All the methods are implicitly public No need to public specifier 8JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Interface Implementation Some classes may inherit abstract classes Some classes may implement interfaces Is-a relation exists If a class implements an interface But does not implement all the methods What will happen? The class becomes an abstract class 9JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

10JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Multiple Inheritance in Java A class can inherit one and only one class A class may implement zero or more interfaces 11JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

12JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

A Question Why multiple inheritance is not supported for classes? Why multiple inheritance is supported for interfaces? 13JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

What About Name Collision? 14 The return types are incompatible for the inherited methods B.f(), A.f() JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

15JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Interface Extension Interfaces may inherit other interfaces Code reuse Is-a relation 16JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Interface properties No member variable Variables : implicitly final and static Usually interfaces declare no variable Only operations are declared No constructor Why? 17JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Example 18JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Interfaces Applications Pure Abstract classes Describe the design The architect designs interfaces, the programmer implements them Only interfaces are delivered to code consumers More powerful inheritance and polymorphism 19JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

20JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

21JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

Quiz! 22JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

References Compiler Error A a; B b; C c; D d; c = d; d = c; b = d; d = b; a.f(); 23 d = new D(); d = new E(); c= new E(); b = new E(); a = b; b.f(); OK JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

24JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source