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)

Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 

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.