Advanced Programming in Java

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Session 07: C# OOP 4 Review of: Inheritance and Polymorphism. Static and dynamic type of an object. Abstract Classes. Interfaces. FEN AK - IT:
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
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.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Inheritance in the Java programming language J. W. Rider.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
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.
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.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
©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.
Inheritance.
Advanced Programming in Java
Programming in Java: lecture 7
Modern Programming Tools And Techniques-I
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
Interfaces.
Inheritance and Polymorphism
Advanced Programming in Java
Week 4 Object-Oriented Programming (1): Inheritance
UML Class Diagram: class Rectangle
Functional Programming with Java
Object Oriented Programming
Chapter 10 Thinking in Objects
Interfaces.
CS240: Advanced Programming Concepts
Abstract classes and interfaces
Interface.
Enumerations & Annotations
MSIS 670 Object-Oriented Software Engineering
Inheritance, Polymorphism, and Interfaces. Oh My
Abstract Classes AKEEL AHMED.
Interfaces.
Advanced Programming Behnam Hatami Fall 2017.
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Advanced Java Programming
Multiple Inheritance & Interfaces
Inheritance Inheritance is a fundamental Object Oriented concept
Java Inheritance.
Advanced Programming in Java
Enumerations & Annotations
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Fundaments of Game Design
Chapter 14 Abstract Classes and Interfaces
Abstract classes and interfaces
AP Computer Science DYRT Quiz
Lecture 10 Concepts of Programming Languages
Agenda Inheritance Polymorphism Type compatibility Homework.
Presentation transcript:

Advanced Programming in Java Interfaces Mehdi Einali

agenda interface Multiple Inheritance

interface

Abstract Example

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

Interface Sometimes we have an abstract class, with no concrete method interface : pure abstract class no implemented method

Interface

Interface All the methods are implicitly abstract No need to abstract specifier All the methods are implicitly public No need to public specifier

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

Multiple inheritance

Multiple Inheritance in Java A class can inherit one and only one class A class may implement zero or more interfaces

A Question Why multiple inheritance is not supported for classes? Why multiple inheritance is supported for interfaces?

What About Name Collision? The return types are incompatible for the inherited methods B.f(), A.f()

Interface Extension Interfaces may inherit other interfaces Code reuse Is-a relation

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?

Example

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(abstract coupling)

Quiz Compiler Error References OK A a; B b; C c; D d; d = new D(); d = new E(); c= new E(); b = new E(); a = b; b.f(); c = d; d = c; b = d; d = b; a.f();

End