SlideShare a Scribd company logo
1 of 11
INTERFACES AND
ABSTRACT CLASSES
AKANSH SINGHAL
Abstract Class Real Life Example
Interface Using real Example
Prototype===Interface Class Implementing Interface
output:-
Second Show call
Syntax and use of abstract classes
package ppt;
abstract class First
{
abstract void show(){ };
}
class Second extends First
{
void show()
{
System.out.println(“Second Show call");
}
}
public class Abstractclass {
public static void main(String[]args) {
Second y=new Second();
y.show();
}
}
package ppt;
interface X //interface
{
void show(); //abstract method in interface
}
class Y implements X /*implementing interface X
{ using class Y*/
public void show() {
System.out.println("show call X");
}
}
public class Testinterface {
public static void main(String[] args) {
X obj =new Y(); // creating object of Y having type
obj.show(); X
}
}
Syntax
and use
of
interface
Output:--
show call X
Abstract class
 Abstract class can extend
only one class or one abstract
class at a time
 Abstract class can extend
from a class or from an
abstract class
 Abstract class can have
both abstract and concrete
methods
 A class can extend only one
abstract class
 In abstract class keyword
‘abstract’ is mandatory to
declare a method as an
abstract
Interface
 Interface can extend any
number of interfaces at a time
 Interface can extend only
from an interface
 Interface can have only
abstract methods
 A class can implement any
number of interfaces
 In an interface keyword
‘abstract’ is optional to
declare a method as an
abstract
Abstract Class
 Abstract class can
have protected , public and
private abstract methods.
 Abstract class can have static,
final or static final variable with
any access specifier.
 Constructor is there in abstract
classes.
 Constructor of abstract class not
called directly(can be called using
super)
Interface
 Interface can have only public
abstract methods i.e. By default.
 Interface can have only static final
(constant) variable i.e. By default.
 Constructor is not there in
interface.
 No constructor no object.
Abstract Classes are not 100% abstract whereas
interface is 100% abstract
package ppt;
abstract class First
{
abstract void show(); //abstract
method
void print(){
System.out.println(“Print call");
} //concrete method
}
}
class Second extends First
{
void show()
{
System.out.println(“Second
Show call");
}
}
public class Abstractclass {
public static void main(String[]args) {
Second y=new Second();
y.show();
y.print();
}
}
Output:-
Second Show call
Print call
Abstract Classes are not 100% abstract whereas
interface is 100% abstract
package ppt;
interface X //interface
{
void show(); /*abstract method in
void print(); interface*/
}
class Y implements X
/*implementing interface X
using class Y*/
{
public void show() {
System.out.println("show call Y");
}
public void print() {
System.out.println(“print call Y");
}
}
public class Testinterface {
public static void main(String[] args) {
X obj =new Y(); /* creating object of Y
obj.show(); having type X*/
obj.print();
}
}
Output:--
show call Y
print call Y
The
end

More Related Content

What's hot

Inline function
Inline functionInline function
Inline function
Tech_MX
 

What's hot (20)

C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and PitfallsJava Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and Pitfalls
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
Access Modifier.pptx
Access Modifier.pptxAccess Modifier.pptx
Access Modifier.pptx
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Java packages
Java packagesJava packages
Java packages
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 
Inline function
Inline functionInline function
Inline function
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
 
C# Constructors
C# ConstructorsC# Constructors
C# Constructors
 
Java basic
Java basicJava basic
Java basic
 
OOP java
OOP javaOOP java
OOP java
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 

Similar to Interfaces and abstract classes

Similar to Interfaces and abstract classes (20)

abstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploadabstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx upload
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
 
Interface
InterfaceInterface
Interface
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 
Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdf
 
Interface
InterfaceInterface
Interface
 
Java interface
Java interfaceJava interface
Java interface
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
Java interface
Java interfaceJava interface
Java interface
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
Interface in java
Interface in javaInterface in java
Interface in java
 
JAVA.pptx
JAVA.pptxJAVA.pptx
JAVA.pptx
 
Binding,interface,abstarct class
Binding,interface,abstarct classBinding,interface,abstarct class
Binding,interface,abstarct class
 
Session 6_Java Interfaces_Details_Programs.pdf
Session 6_Java Interfaces_Details_Programs.pdfSession 6_Java Interfaces_Details_Programs.pdf
Session 6_Java Interfaces_Details_Programs.pdf
 
Session 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .pptSession 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .ppt
 
Session 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .pptSession 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .ppt
 
Creating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docxCreating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docx
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 

Interfaces and abstract classes

  • 2. Abstract Class Real Life Example
  • 3. Interface Using real Example Prototype===Interface Class Implementing Interface
  • 4. output:- Second Show call Syntax and use of abstract classes package ppt; abstract class First { abstract void show(){ }; } class Second extends First { void show() { System.out.println(“Second Show call"); } } public class Abstractclass { public static void main(String[]args) { Second y=new Second(); y.show(); } }
  • 5. package ppt; interface X //interface { void show(); //abstract method in interface } class Y implements X /*implementing interface X { using class Y*/ public void show() { System.out.println("show call X"); } } public class Testinterface { public static void main(String[] args) { X obj =new Y(); // creating object of Y having type obj.show(); X } } Syntax and use of interface Output:-- show call X
  • 6. Abstract class  Abstract class can extend only one class or one abstract class at a time  Abstract class can extend from a class or from an abstract class  Abstract class can have both abstract and concrete methods  A class can extend only one abstract class  In abstract class keyword ‘abstract’ is mandatory to declare a method as an abstract Interface  Interface can extend any number of interfaces at a time  Interface can extend only from an interface  Interface can have only abstract methods  A class can implement any number of interfaces  In an interface keyword ‘abstract’ is optional to declare a method as an abstract
  • 7. Abstract Class  Abstract class can have protected , public and private abstract methods.  Abstract class can have static, final or static final variable with any access specifier.  Constructor is there in abstract classes.  Constructor of abstract class not called directly(can be called using super) Interface  Interface can have only public abstract methods i.e. By default.  Interface can have only static final (constant) variable i.e. By default.  Constructor is not there in interface.  No constructor no object.
  • 8. Abstract Classes are not 100% abstract whereas interface is 100% abstract package ppt; abstract class First { abstract void show(); //abstract method void print(){ System.out.println(“Print call"); } //concrete method } } class Second extends First { void show() { System.out.println(“Second Show call"); } } public class Abstractclass { public static void main(String[]args) { Second y=new Second(); y.show(); y.print(); } } Output:- Second Show call Print call
  • 9. Abstract Classes are not 100% abstract whereas interface is 100% abstract package ppt; interface X //interface { void show(); /*abstract method in void print(); interface*/ } class Y implements X /*implementing interface X using class Y*/ { public void show() { System.out.println("show call Y"); } public void print() { System.out.println(“print call Y"); } } public class Testinterface { public static void main(String[] args) { X obj =new Y(); /* creating object of Y obj.show(); having type X*/ obj.print(); } } Output:-- show call Y print call Y
  • 10.