Download presentation
Presentation is loading. Please wait.
Published bySherilyn Lester Modified over 9 years ago
1
Sadegh Aliakbary Sharif University of Technology Fall 2010
2
Agenda interface Multiple Inheritance Fall 2010Sharif University of Technology2
3
Review : Abstract Abstract Methods No Implementation Sub-classes may implement abstract methods Abstract Classes A class with one or more abstract methods Can not be instantiated A class which extends an abstract class Is abstract unless it implements all the abstract methods Concrete class Not abstract class Fall 2010Sharif University of Technology3
4
Abstract Example Fall 2010Sharif University of Technology4
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 Fall 2010Sharif University of Technology5
6
Interface Sometimes we have an abstract class, with no concrete method interface : pure abstract class no implemented method Fall 2010Sharif University of Technology6
7
Interface Fall 2010Sharif University of Technology7
8
Interface All the methods are implicitly abstract No need to abstract specifier All the methods are implicitly public No need to public specifier Fall 2010Sharif University of Technology8
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 became an abstract class Fall 2010Sharif University of Technology9
10
Fall 2010Sharif University of Technology10
11
Multiple Inheritance in Java A class can inherit one and only one class A class may implement zero or more interfaces Fall 2010Sharif University of Technology11
12
Fall 2010Sharif University of Technology12
13
A Question Why multiple inheritance is not supported for classes? Why multiple inheritance is supported for interfaces? Fall 2010Sharif University of Technology13
14
What About Name Collision? Fall 2010Sharif University of Technology14 The return types are incompatible for the inherited methods B.f(), A.f()
15
Fall 2010Sharif University of Technology15
16
Interface Extension Interfaces may inherit other interfaces Code reuse Is-a relation Fall 2010Sharif University of Technology16
17
Interface properties No member variable Variables : implicitly final and static Usually interfaces declare no variable Only operations are declared No constructor Why? Fall 2010Sharif University of Technology17
18
Example Fall 2010Sharif University of Technology18
19
Interfaces Applications Pure Abstract classes Describe the design More powerful inheritance and polymorphism Fall 2010Sharif University of Technology19
20
Quiz! Fall 2010Sharif University of Technology20
21
Fall 2010Sharif University of Technology21
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.