SlideShare a Scribd company logo
Interfaces & Abstract classes
Interface Java’s interfaces are an improvement over multiple inheritance mechanism of C++. While designing a software system in java, Interfaces help us defining the interfaces between the components. Interfaces help us achieve a special kind of multiple inheritance : multiple inheritance of interfaces without multiple inheritance of implementation.
Which is a better design pattern? Multiple inheritance of interfaces    or Multiple inheritance of classes (implementations). Interfaces solve Diamond Problem with traditional multiple inheritance.
abstract class Animal  { abstract void talk(); }  class Frog extends Animal {  void talk()  {  System.out.println("Ribit, ribit."); } }  class Dinosaur extends Animal  {  void talk()  {  System.out.println("Oh I'm a dinosaur and I'm OK...");  }  }  // This won't compile, of course, because //Java  only supports single inheritance.  class Frogosaur extends Frog, Dinosaur { }  Animal animal = new Frogosaur(); animal.talk();  When we think of objects, We assume it as programmatic representations of real-world entities. Confused, isn’t it ?
Think Animal would have declared a public instance variable, which Frogosaur would then have inherited from both Dinosaur and Frog. When referring to this variable in a Frogosaur object, which copy of the variable -- Frog's or Dinosaur's -- would have been selected?  We solve all these ambiguities in software design using interfaces in Java. Through interfaces, Java allows multiple inheritance of interfaces but not of implementations. Implementation, which includes instance variables and method implementations, is always singly inherited.
Interfaces & Polymorphism We learned, Interface is the Java’s way to solve diamond problem. But is this the only benefit?? Interface also lets us take greater advantage of polymorphism in our designs, which in turn helps us make our software more flexible.
What’s this Polymorphism? A greek word meaning many shapes. In context of Java, a class has many forms: that of the class and any of its subclasses.   An Animal, for example, can look like a Dog or a Cat or any other subclass of Animal. It also means using a superclass variable to refer to a subclass object. For Ex:- abstract class Animal { abstract void talk(); } class Dog extends Animal { void talk() { System.out.println("Woof!"); } } class Cat extends Animal { void talk() { System.out.println("Meow."); } } class Interrogator { static void makeItTalk(Animal subject) { subject.talk(); } }
Polymorphism  contd. Types : 2 1. Compile-time Polymorphism 2. Runtime Polymorphism Think, In the previous ex. the compiler knows only : an object of some Animal subclass will be made available to makeItTalk(). It means, JVM will decide at runtime which method to invoke based on the class. How is our program going to be flexible this way? Think of adding some more classes as the one below …..   class Bird extends Animal { void talk() { System.out.println("Tweet, tweet!"); } } Do we need to change the makeItTalk() method??
Polymorphism  contd. Getting more Polymorphism: Interfaces give us more polymorphism than singly inherited families of classes,  because with interfaces we don't have to make everything fit into one family of classes. interface Talkative { void talk(); } abstract class Animal implements Talkative { abstract public void talk(); } class Dog extends Animal { public void talk() { System.out.println("Woof!"); } } class Cat extends Animal { public void talk() { System.out.println("Meow."); } } class Interrogator { static void makeItTalk(Talkative subject) { subject.talk(); } }
Polymorphism  contd. Here is the magic!! class Clock { } class CuckooClock  implements Talkative  { public void talk() { System.out.println("Cuckoo, cuckoo!"); } } class Test { public static void main(String[] args) { CuckooClock cc = new CuckooClock(); Interrogator.makeItTalk(cc); } }
Polymorphism  contd. Conclusion :- With single inheritance only, we'd either have to somehow fit CuckooClock into the Animal family, or not use polymorphism.  With interfaces, any class in any family can implement Talkative and be passed to makeItTalk().  This is why we say interfaces provide  more polymorphism  than we can get with singly inherited families of classes.
Using Interfaces Variables declared in the interfaces are implicitly  public, static & final. Methods declared in the interfaces are implicitly  public & abstract. Following modifiers can’t be applied to the methods declared in an interface :- private, protected, static, final, synchronized Variables declared in an interface  can’t be private or protected. An interface can extend one or more interfaces. One or more interfaces can be implemented in a class.
Ad

More Related Content

What's hot (20)

Inheritance
InheritanceInheritance
Inheritance
Sapna Sharma
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
Mutinda Boniface
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
Tamanna Akter
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
BHUVIJAYAVELU
 
The Ring programming language version 1.5.3 book - Part 6 of 184
The Ring programming language version 1.5.3 book - Part 6 of 184The Ring programming language version 1.5.3 book - Part 6 of 184
The Ring programming language version 1.5.3 book - Part 6 of 184
Mahmoud Samir Fayed
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
tigerwarn
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
Atul Sehdev
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
Kurapati Vishwak
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
Dot Com Infoway - Custom Software, Mobile, Web Application Development and Digital Marketing Company
 
Java essence part 1
Java essence part 1Java essence part 1
Java essence part 1
HanRu Yeh
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Codemotion
 
The Ring programming language version 1.5.4 book - Part 6 of 185
The Ring programming language version 1.5.4 book - Part 6 of 185The Ring programming language version 1.5.4 book - Part 6 of 185
The Ring programming language version 1.5.4 book - Part 6 of 185
Mahmoud Samir Fayed
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - Inheritance
Oum Saokosal
 
Applets
AppletsApplets
Applets
Ravi Kant Sahu
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
tayyaba nawaz
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)
Ravi Kant Sahu
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
The Ring programming language version 1.5.3 book - Part 6 of 184
The Ring programming language version 1.5.3 book - Part 6 of 184The Ring programming language version 1.5.3 book - Part 6 of 184
The Ring programming language version 1.5.3 book - Part 6 of 184
Mahmoud Samir Fayed
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
tigerwarn
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
Atul Sehdev
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
Kurapati Vishwak
 
Java essence part 1
Java essence part 1Java essence part 1
Java essence part 1
HanRu Yeh
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Codemotion
 
The Ring programming language version 1.5.4 book - Part 6 of 185
The Ring programming language version 1.5.4 book - Part 6 of 185The Ring programming language version 1.5.4 book - Part 6 of 185
The Ring programming language version 1.5.4 book - Part 6 of 185
Mahmoud Samir Fayed
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - Inheritance
Oum Saokosal
 
String handling(string buffer class)
String handling(string buffer class)String handling(string buffer class)
String handling(string buffer class)
Ravi Kant Sahu
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 

Viewers also liked (14)

Policy brief vending machines at school
Policy brief vending machines at schoolPolicy brief vending machines at school
Policy brief vending machines at school
Christine Drake, MBA
 
Synergy pProfile aAug2016
Synergy pProfile aAug2016Synergy pProfile aAug2016
Synergy pProfile aAug2016
Prashant Kaushal
 
Synergy profile
Synergy profileSynergy profile
Synergy profile
Prashant Kaushal
 
El golpe Larense
El golpe LarenseEl golpe Larense
El golpe Larense
Dairy torrealba
 
Business Plan---267
Business Plan---267Business Plan---267
Business Plan---267
Zach DiSilva
 
Heroku Demo
Heroku DemoHeroku Demo
Heroku Demo
Melissa Hansen
 
EFARD Mid-Term Report
EFARD Mid-Term ReportEFARD Mid-Term Report
EFARD Mid-Term Report
Technical Centre for Agricultural and Rural Cooperation ACP-EU (CTA)
 
Mc18 Zebra
Mc18 ZebraMc18 Zebra
Mc18 Zebra
ScanSource Brasil
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Short notes of oop with java
Short notes of oop with javaShort notes of oop with java
Short notes of oop with java
Mohamed Fathy
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
OUM SAOKOSAL
 
PAEPARD Users' Led Process
PAEPARD Users' Led ProcessPAEPARD Users' Led Process
PAEPARD Users' Led Process
Technical Centre for Agricultural and Rural Cooperation ACP-EU (CTA)
 
Surf and Sun - Surfing in South Australia
Surf and Sun - Surfing in South AustraliaSurf and Sun - Surfing in South Australia
Surf and Sun - Surfing in South Australia
Ashley Smith
 
Ad

Similar to Interfaces & Abstract Classes (20)

Java Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHatJava Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHat
Scholarhat
 
Java
JavaJava
Java
Ashen Disanayaka
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
Sherihan Anver
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
Rich Helton
 
Introduction To Java.
Introduction To Java.Introduction To Java.
Introduction To Java.
Tushar Chauhan
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
PrasannaKumar Sathyanarayanan
 
The smartpath information systems java
The smartpath information systems javaThe smartpath information systems java
The smartpath information systems java
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVM
Andres Almiray
 
Chapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUI
Chapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUIChapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUI
Chapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUI
berihun18
 
Objects and classes in OO Programming concepts
Objects and classes in OO Programming conceptsObjects and classes in OO Programming concepts
Objects and classes in OO Programming concepts
researchveltech
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
Intro C# Book
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
Jady Yang
 
Polyglot Programming @ Jax.de 2010
Polyglot Programming @ Jax.de 2010Polyglot Programming @ Jax.de 2010
Polyglot Programming @ Jax.de 2010
Andres Almiray
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
How would you implement multiple inheritance in java
How would you implement multiple inheritance in javaHow would you implement multiple inheritance in java
How would you implement multiple inheritance in java
Tyagi2636
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
Abid Kohistani
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
SAurabh PRajapati
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
RudranilDas11
 
Java Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHatJava Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHat
Scholarhat
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
Sherihan Anver
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
Rich Helton
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVM
Andres Almiray
 
Chapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUI
Chapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUIChapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUI
Chapter5.pptxfghwryhYETHYETH67IOIKUTJJUILOUI
berihun18
 
Objects and classes in OO Programming concepts
Objects and classes in OO Programming conceptsObjects and classes in OO Programming concepts
Objects and classes in OO Programming concepts
researchveltech
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
Intro C# Book
 
Xopus Application Framework
Xopus Application FrameworkXopus Application Framework
Xopus Application Framework
Jady Yang
 
Polyglot Programming @ Jax.de 2010
Polyglot Programming @ Jax.de 2010Polyglot Programming @ Jax.de 2010
Polyglot Programming @ Jax.de 2010
Andres Almiray
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
How would you implement multiple inheritance in java
How would you implement multiple inheritance in javaHow would you implement multiple inheritance in java
How would you implement multiple inheritance in java
Tyagi2636
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
Abid Kohistani
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
SAurabh PRajapati
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
RudranilDas11
 
Ad

More from Bharat17485 (12)

Channel Based Io
Channel Based IoChannel Based Io
Channel Based Io
Bharat17485
 
Core Java
Core JavaCore Java
Core Java
Bharat17485
 
Developing Multithreaded Applications
Developing Multithreaded ApplicationsDeveloping Multithreaded Applications
Developing Multithreaded Applications
Bharat17485
 
Enum
EnumEnum
Enum
Bharat17485
 
Exceptions & Its Handling
Exceptions & Its HandlingExceptions & Its Handling
Exceptions & Its Handling
Bharat17485
 
Jstl & El
Jstl & ElJstl & El
Jstl & El
Bharat17485
 
Primitive Wrappers
Primitive WrappersPrimitive Wrappers
Primitive Wrappers
Bharat17485
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
Bharat17485
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
Bharat17485
 
String Handling
String HandlingString Handling
String Handling
Bharat17485
 
Swing
SwingSwing
Swing
Bharat17485
 
Applying Generics
Applying GenericsApplying Generics
Applying Generics
Bharat17485
 
Channel Based Io
Channel Based IoChannel Based Io
Channel Based Io
Bharat17485
 
Developing Multithreaded Applications
Developing Multithreaded ApplicationsDeveloping Multithreaded Applications
Developing Multithreaded Applications
Bharat17485
 
Exceptions & Its Handling
Exceptions & Its HandlingExceptions & Its Handling
Exceptions & Its Handling
Bharat17485
 
Primitive Wrappers
Primitive WrappersPrimitive Wrappers
Primitive Wrappers
Bharat17485
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
Bharat17485
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
Bharat17485
 
Applying Generics
Applying GenericsApplying Generics
Applying Generics
Bharat17485
 

Recently uploaded (20)

IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
DNF 2.0 Implementations Challenges in Nepal
DNF 2.0 Implementations Challenges in NepalDNF 2.0 Implementations Challenges in Nepal
DNF 2.0 Implementations Challenges in Nepal
ICT Frame Magazine Pvt. Ltd.
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptxUiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
anabulhac
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
ACE Aarhus - Team'25 wrap-up presentation
ACE Aarhus - Team'25 wrap-up presentationACE Aarhus - Team'25 wrap-up presentation
ACE Aarhus - Team'25 wrap-up presentation
DanielEriksen5
 
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Cyntexa
 
MEMS IC Substrate Technologies Guide 2025.pptx
MEMS IC Substrate Technologies Guide 2025.pptxMEMS IC Substrate Technologies Guide 2025.pptx
MEMS IC Substrate Technologies Guide 2025.pptx
IC substrate Shawn Wang
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Alan Dix
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdfKit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Kit-Works Team Study_팀스터디_김한솔_nuqs_20250509.pdf
Wonjun Hwang
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptxUiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
anabulhac
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
ACE Aarhus - Team'25 wrap-up presentation
ACE Aarhus - Team'25 wrap-up presentationACE Aarhus - Team'25 wrap-up presentation
ACE Aarhus - Team'25 wrap-up presentation
DanielEriksen5
 
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Cyntexa
 
MEMS IC Substrate Technologies Guide 2025.pptx
MEMS IC Substrate Technologies Guide 2025.pptxMEMS IC Substrate Technologies Guide 2025.pptx
MEMS IC Substrate Technologies Guide 2025.pptx
IC substrate Shawn Wang
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Alan Dix
 

Interfaces & Abstract Classes

  • 2. Interface Java’s interfaces are an improvement over multiple inheritance mechanism of C++. While designing a software system in java, Interfaces help us defining the interfaces between the components. Interfaces help us achieve a special kind of multiple inheritance : multiple inheritance of interfaces without multiple inheritance of implementation.
  • 3. Which is a better design pattern? Multiple inheritance of interfaces or Multiple inheritance of classes (implementations). Interfaces solve Diamond Problem with traditional multiple inheritance.
  • 4. abstract class Animal { abstract void talk(); } class Frog extends Animal { void talk() { System.out.println("Ribit, ribit."); } } class Dinosaur extends Animal { void talk() { System.out.println("Oh I'm a dinosaur and I'm OK..."); } } // This won't compile, of course, because //Java only supports single inheritance. class Frogosaur extends Frog, Dinosaur { } Animal animal = new Frogosaur(); animal.talk(); When we think of objects, We assume it as programmatic representations of real-world entities. Confused, isn’t it ?
  • 5. Think Animal would have declared a public instance variable, which Frogosaur would then have inherited from both Dinosaur and Frog. When referring to this variable in a Frogosaur object, which copy of the variable -- Frog's or Dinosaur's -- would have been selected? We solve all these ambiguities in software design using interfaces in Java. Through interfaces, Java allows multiple inheritance of interfaces but not of implementations. Implementation, which includes instance variables and method implementations, is always singly inherited.
  • 6. Interfaces & Polymorphism We learned, Interface is the Java’s way to solve diamond problem. But is this the only benefit?? Interface also lets us take greater advantage of polymorphism in our designs, which in turn helps us make our software more flexible.
  • 7. What’s this Polymorphism? A greek word meaning many shapes. In context of Java, a class has many forms: that of the class and any of its subclasses. An Animal, for example, can look like a Dog or a Cat or any other subclass of Animal. It also means using a superclass variable to refer to a subclass object. For Ex:- abstract class Animal { abstract void talk(); } class Dog extends Animal { void talk() { System.out.println("Woof!"); } } class Cat extends Animal { void talk() { System.out.println("Meow."); } } class Interrogator { static void makeItTalk(Animal subject) { subject.talk(); } }
  • 8. Polymorphism contd. Types : 2 1. Compile-time Polymorphism 2. Runtime Polymorphism Think, In the previous ex. the compiler knows only : an object of some Animal subclass will be made available to makeItTalk(). It means, JVM will decide at runtime which method to invoke based on the class. How is our program going to be flexible this way? Think of adding some more classes as the one below ….. class Bird extends Animal { void talk() { System.out.println("Tweet, tweet!"); } } Do we need to change the makeItTalk() method??
  • 9. Polymorphism contd. Getting more Polymorphism: Interfaces give us more polymorphism than singly inherited families of classes, because with interfaces we don't have to make everything fit into one family of classes. interface Talkative { void talk(); } abstract class Animal implements Talkative { abstract public void talk(); } class Dog extends Animal { public void talk() { System.out.println("Woof!"); } } class Cat extends Animal { public void talk() { System.out.println("Meow."); } } class Interrogator { static void makeItTalk(Talkative subject) { subject.talk(); } }
  • 10. Polymorphism contd. Here is the magic!! class Clock { } class CuckooClock implements Talkative { public void talk() { System.out.println("Cuckoo, cuckoo!"); } } class Test { public static void main(String[] args) { CuckooClock cc = new CuckooClock(); Interrogator.makeItTalk(cc); } }
  • 11. Polymorphism contd. Conclusion :- With single inheritance only, we'd either have to somehow fit CuckooClock into the Animal family, or not use polymorphism. With interfaces, any class in any family can implement Talkative and be passed to makeItTalk(). This is why we say interfaces provide more polymorphism than we can get with singly inherited families of classes.
  • 12. Using Interfaces Variables declared in the interfaces are implicitly public, static & final. Methods declared in the interfaces are implicitly public & abstract. Following modifiers can’t be applied to the methods declared in an interface :- private, protected, static, final, synchronized Variables declared in an interface can’t be private or protected. An interface can extend one or more interfaces. One or more interfaces can be implemented in a class.
  翻译: