Advanced Programming in Java

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
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.
Interface & Abstract Class. Interface Definition All method in an interface are abstract methods. Methods are declared without the implementation part.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
UML Class Diagram: class Rectangle
Chapter 10 Classes Continued
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
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.
Inheritance using Java
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
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 Sharif University of Technology Fall 2010.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
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.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
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.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Peyman Dodangeh Sharif University of Technology Fall 2014.
C# G 1 CSC 298 Object Oriented Programming Part 2.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Inheritance 2 Mehdi Einali Advanced Programming in Java 1.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
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.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
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.
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
Abstract classes and interfaces
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
University of Central Florida COP 3330 Object Oriented Programming
Interface, Subclass, and Abstract Class Review
One class is an extension of another.
UML Class Diagram: class Rectangle
Chapter 10 Thinking in Objects
One class is an extension of another.
Abstract classes and interfaces
Inheritance, Polymorphism, and Interfaces. Oh My
Interfaces.
Advanced Programming Behnam Hatami Fall 2017.
Abstract Classes Page
Advanced Programming in Java
Java Inheritance.
Advanced Programming in Java
Chapter 14 Abstract Classes and Interfaces
Abstract classes and interfaces
Lecture 10 Concepts of Programming Languages
Presentation transcript:

Advanced Programming in Java Salman Marvasti Sharif University of Technology Winter 2015

Agenda interface Multiple Inheritance Fall 2014 Sharif University of Technology

Review : Abstract Abstract Methods Abstract Classes No Implementation Sub-classes may implement abstract methods Abstract Classes Can not be instantiated (Usually) A class with one or more abstract methods A class which extends an abstract class Is abstract unless it implements all the abstract methods Concrete class  Not abstract class Fall 2014 Sharif University of Technology

Abstract Example Fall 2014 Sharif University of Technology

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 2014 Sharif University of Technology

Interface Sometimes we have an abstract class, with no concrete method interface : pure abstract class no implemented method Fall 2014 Sharif University of Technology

Interface Fall 2014 Sharif University of Technology

Interface All the methods are implicitly abstract No need to abstract specifier All the methods are implicitly public No need to public specifier Fall 2014 Sharif University of Technology

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 Fall 2014 Sharif University of Technology

Fall 2014 Sharif University of Technology

Multiple Inheritance in Java A class can inherit one and only one class A class may implement zero or more interfaces Fall 2014 Sharif University of Technology

Fall 2014 Sharif University of Technology

A Question Why multiple inheritance is not supported for classes? Why multiple inheritance is supported for interfaces? Fall 2014 Sharif University of Technology

What About Name Collision? The return types are incompatible for the inherited methods B.f(), A.f() Fall 2014 Sharif University of Technology

Fall 2014 Sharif University of Technology

Interface Extension Interfaces may inherit other interfaces Code reuse Is-a relation Fall 2014 Sharif University of Technology

Interface properties No member variable Only operations are declared Variables : implicitly final and static Usually interfaces declare no variable Only operations are declared No constructor Why? Fall 2014 Sharif University of Technology

Example Fall 2014 Sharif University of Technology

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 Fall 2014 Sharif University of Technology

Fall 2012 Sharif University of Technology