Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Www.javacup.ir Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP."— Presentation transcript:

1 www.javacup.ir Sadegh Aliakbary

2 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 info@javacup.irinfo@javacup.ir 2JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source

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

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

5 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

6 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

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

8 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

9 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

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

11 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

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

13 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

14 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

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

16 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

17 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

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

19 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

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

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

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

23 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

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


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

Similar presentations


Ads by Google