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