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

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.
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:
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
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.
Inheritance using Java
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.
Inheritance in the Java programming language J. W. Rider.
Peyman Dodangeh Sharif University of Technology Fall 2014.
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 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.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Interfaces Are used to model weak inheritance relationships Object-inheritance.
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.
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
Sections Inheritance and Abstract Classes
Advanced Programming in Java
University of Central Florida COP 3330 Object Oriented Programming
Interface, Subclass, and Abstract Class Review
Inheritance and Polymorphism
Interfaces Professor Evan Korth.
Week 4 Object-Oriented Programming (1): Inheritance
UML Class Diagram: class Rectangle
Nested class.
Object Oriented Programming
Chapter 10 Thinking in Objects
Interfaces.
Abstract classes and interfaces
Interface.
MSIS 670 Object-Oriented Software Engineering
Inheritance, Polymorphism, and Interfaces. Oh My
Interfaces.
Advanced Programming Behnam Hatami Fall 2017.
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Advanced Java Programming
Advanced Programming in Java
Inheritance Inheritance is a fundamental Object Oriented concept
Java Inheritance.
Advanced Programming in Java
Topic 10 Abstract Classes “I prefer Agassiz in the abstract,
Fundaments of Game Design
Chapter 14 Abstract Classes and Interfaces
Abstract classes and interfaces
Assessment – Java Basics: Part 2
OOP Aga private institute for computer science 5th grade
Lecture 10 Concepts of Programming Languages
Presentation transcript:

Advanced Programming in Java Peyman Dodangeh Sharif University of Technology Fall 2014

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