SlideShare a Scribd company logo
Session-3A
● This module introduces patcipants to the java
interface.
● Describes inheritence of interfaces
● creation of objects to interfaces.
● Abstract classes
Module Overview
2
Interface
An interface is an abstract data type that defines a list of abstract public
methods that any class implementing the interface must provide. An
interface can also include a list of constant variables and default
methods.
•Interface is defined with the interface keyword.
• Interfaces cannot be instantiated directly.
• An interface is not required to have any methods and may not be
marked as final.
•All nondefault methods in an interface are assumed to have the
modifiers abstract and public in their definition.
• All top-level interfaces are assumed to have public or default
access, and they must include the abstract modifier in their
definition.
•Marking an interface as private, protected, or final will trigger a
compiler error, since this is incompatible with these assumptions.
Interface
//abstract method means unimplementation or no
implementation
public interface Person {
public final static String country="India";
public abstract boolean
isHospitalised();//unimplemented methods
}
Interface Variables
Interface variables rules:
1. Interface variables are assumed to be public, static, and
final. Therefore, marking a variable as private or
protected will trigger a compiler error, as will marking
any variable as abstract.
2. The value of an interface variable must be set when it is
declared since it is marked as final.
Interface Inheritence
Inheritance rules when extending an interface:
1. An interface that extends another interface, as well as an
abstract class that implements an interface, inherits all of the
abstract methods as its own abstract methods.
2. The first concrete class that implements an interface, or extends
an abstract class that implements an interface, must provide an
implementation for all of the inherited abstract methods.
Inheritence example
//abstract method means unimplementation or no
implementation
public interface Person extends
PhysicallyChallenged,Resident{
public final static String country="India";
public abstract boolean
isHospitalised();//unimplemented methods
}
Default Method(java 8)
A default method is a method defi ned within an
interface with the default keyword in which a method
body is provided. Contrast default methods with
“regular” methods in an interface, which are assumed to
be abstract and may not have a method body.
A default method within an interface defi nes an abstract
method with a default implementation. In this manner,
classes have the option to override the default method if
they need to, but they are not required to do so. If the
class doesn’t override the method, the default
implementation will be used.
Default Method Example
public interface IsAdmitted{
boolean hasInsurance();
public default double getBill() {
return 1000.0;
}
}
Note:- methods of an interface are always public.
Default method rules
1. A default method may only be declared within an
interface and not within a class or abstract class.
2. A default method must be marked with the default
keyword. If a method is marked as default, it must
provide a method body.
3. A default method is not assumed to be static, final, or
abstract, as it may be used or overridden by a class that
implements the interface.
4. Like all methods in an interface, a default method is
assumed to be public and will not compile if marked as
private or protected.
Static methods in Interface(java 8)
Static methods are defi ned explicitly with the static
keyword.
There is one distinction between a static method in a class
and an interface.
A static method defi ned in an interface is not inherited
in any classes that implement the interface.
Here are the static interface method rules you need to be
familiar with:
1. Like all methods in an interface, a static method is
assumed to be public and will not compile if marked as
private or protected.
2. 2. To reference the static method, a reference to the
name of the interface must be used.
Static Method Example
public interface Discharge{
static int no_Of_Days_Admit() {
return 10;
}
}
Polymorphism
Polymorphism is a oops feature in which the property of
an object takes on many different forms.
No of ways polymorphism achieved:
Java object may be accessed using a reference with the
same type as the object .
Reference that is a superclass of the object,
Reference that defi nes an interface the object
implements, either directly or through a superclass.
Explicit cast is not required if the object is being
reassigned to a super type or interface of the object
Thank you.

More Related Content

PPT
03_A-OOPs_Interfaces.ppt
PDF
Interfaces in java
DOCX
Master of Computer Application (MCA) – Semester 4 MC0078
PDF
Interface
PDF
this keyword in Java.pdf
PDF
Abstraction in Java: Abstract class and Interfaces
DOC
PPTX
Lecture 18
03_A-OOPs_Interfaces.ppt
Interfaces in java
Master of Computer Application (MCA) – Semester 4 MC0078
Interface
this keyword in Java.pdf
Abstraction in Java: Abstract class and Interfaces
Lecture 18

Similar to 03_A-OOPs_Interfaces.ppt (20)

DOCX
Core java questions
PPTX
this keyword in Java.pptx
PDF
‏‏‏‏‏‏oop lecture 6_١٢٥٩٤٧taiz univercity.pdf
DOCX
Corejavainterviewquestions.doc
PPT
Interfaces
PPTX
OOFeatures_revised-2.pptx
DOC
Java interview questions
DOC
Core java interview questions
PPTX
Interface in Java
PDF
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
PPT
12.2 Abstract class and Interface.ppt
PDF
Java 06
PPTX
Dev labs alliance top 20 basic java interview questions for sdet
PPTX
The smartpath information systems java
PPTX
INTERFACES. with machine learning and data
PPTX
Top 20 basic java interview questions for SDET
PPTX
Dev labs alliance top 20 basic java interview question for sdet
PPTX
it is the quick gest about the interfaces in java
DOC
116824015 java-j2 ee
PPTX
Abstraction encapsulation inheritance polymorphism
Core java questions
this keyword in Java.pptx
‏‏‏‏‏‏oop lecture 6_١٢٥٩٤٧taiz univercity.pdf
Corejavainterviewquestions.doc
Interfaces
OOFeatures_revised-2.pptx
Java interview questions
Core java interview questions
Interface in Java
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
12.2 Abstract class and Interface.ppt
Java 06
Dev labs alliance top 20 basic java interview questions for sdet
The smartpath information systems java
INTERFACES. with machine learning and data
Top 20 basic java interview questions for SDET
Dev labs alliance top 20 basic java interview question for sdet
it is the quick gest about the interfaces in java
116824015 java-j2 ee
Abstraction encapsulation inheritance polymorphism

More from JyothiAmpally (18)

DOCX
node.js interview questions and answers.
PPT
Exception and ErrorHandling in Java .ppt
PPT
Java Strings methods and operations.ppt
PPT
Arrays Basicfundamentaldatastructure.ppt
PPT
_Java__Expressions__and__FlowControl.ppt
PPT
Java-Variables_about_different_Scope.ppt
PPT
Java Operators explained _in __brief.ppt
PPT
UML to Object Oriented Mapping java .ppt
PPT
OOPS_AbstractClasses_explained__java.ppt
PPT
Java_Identifiers_keywords_data_types.ppt
PPT
Java_gui_with_AWT_and_its_components.ppt
PPT
1. Introduction to HTML5.ppt
PPT
01-basics-functions.ppt
PPT
25-functions.ppt
PPT
02-Java Technology Details.ppt
PPT
01-Java Introduction.ppt
PPT
01_What is Java.ppt
DOCX
Spring security
node.js interview questions and answers.
Exception and ErrorHandling in Java .ppt
Java Strings methods and operations.ppt
Arrays Basicfundamentaldatastructure.ppt
_Java__Expressions__and__FlowControl.ppt
Java-Variables_about_different_Scope.ppt
Java Operators explained _in __brief.ppt
UML to Object Oriented Mapping java .ppt
OOPS_AbstractClasses_explained__java.ppt
Java_Identifiers_keywords_data_types.ppt
Java_gui_with_AWT_and_its_components.ppt
1. Introduction to HTML5.ppt
01-basics-functions.ppt
25-functions.ppt
02-Java Technology Details.ppt
01-Java Introduction.ppt
01_What is Java.ppt
Spring security

Recently uploaded (20)

PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Transform Your Business with a Software ERP System
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
ai tools demonstartion for schools and inter college
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Introduction to Artificial Intelligence
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
System and Network Administration Chapter 2
PPTX
history of c programming in notes for students .pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
assetexplorer- product-overview - presentation
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
System and Network Administraation Chapter 3
PDF
Understanding Forklifts - TECH EHS Solution
CHAPTER 2 - PM Management and IT Context
Digital Systems & Binary Numbers (comprehensive )
Transform Your Business with a Software ERP System
Reimagine Home Health with the Power of Agentic AI​
ai tools demonstartion for schools and inter college
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
How to Migrate SBCGlobal Email to Yahoo Easily
Introduction to Artificial Intelligence
Designing Intelligence for the Shop Floor.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
System and Network Administration Chapter 2
history of c programming in notes for students .pptx
Softaken Excel to vCard Converter Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
assetexplorer- product-overview - presentation
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
2025 Textile ERP Trends: SAP, Odoo & Oracle
System and Network Administraation Chapter 3
Understanding Forklifts - TECH EHS Solution

03_A-OOPs_Interfaces.ppt

  • 2. ● This module introduces patcipants to the java interface. ● Describes inheritence of interfaces ● creation of objects to interfaces. ● Abstract classes Module Overview 2
  • 3. Interface An interface is an abstract data type that defines a list of abstract public methods that any class implementing the interface must provide. An interface can also include a list of constant variables and default methods. •Interface is defined with the interface keyword. • Interfaces cannot be instantiated directly. • An interface is not required to have any methods and may not be marked as final. •All nondefault methods in an interface are assumed to have the modifiers abstract and public in their definition. • All top-level interfaces are assumed to have public or default access, and they must include the abstract modifier in their definition. •Marking an interface as private, protected, or final will trigger a compiler error, since this is incompatible with these assumptions.
  • 4. Interface //abstract method means unimplementation or no implementation public interface Person { public final static String country="India"; public abstract boolean isHospitalised();//unimplemented methods }
  • 5. Interface Variables Interface variables rules: 1. Interface variables are assumed to be public, static, and final. Therefore, marking a variable as private or protected will trigger a compiler error, as will marking any variable as abstract. 2. The value of an interface variable must be set when it is declared since it is marked as final.
  • 6. Interface Inheritence Inheritance rules when extending an interface: 1. An interface that extends another interface, as well as an abstract class that implements an interface, inherits all of the abstract methods as its own abstract methods. 2. The first concrete class that implements an interface, or extends an abstract class that implements an interface, must provide an implementation for all of the inherited abstract methods.
  • 7. Inheritence example //abstract method means unimplementation or no implementation public interface Person extends PhysicallyChallenged,Resident{ public final static String country="India"; public abstract boolean isHospitalised();//unimplemented methods }
  • 8. Default Method(java 8) A default method is a method defi ned within an interface with the default keyword in which a method body is provided. Contrast default methods with “regular” methods in an interface, which are assumed to be abstract and may not have a method body. A default method within an interface defi nes an abstract method with a default implementation. In this manner, classes have the option to override the default method if they need to, but they are not required to do so. If the class doesn’t override the method, the default implementation will be used.
  • 9. Default Method Example public interface IsAdmitted{ boolean hasInsurance(); public default double getBill() { return 1000.0; } } Note:- methods of an interface are always public.
  • 10. Default method rules 1. A default method may only be declared within an interface and not within a class or abstract class. 2. A default method must be marked with the default keyword. If a method is marked as default, it must provide a method body. 3. A default method is not assumed to be static, final, or abstract, as it may be used or overridden by a class that implements the interface. 4. Like all methods in an interface, a default method is assumed to be public and will not compile if marked as private or protected.
  • 11. Static methods in Interface(java 8) Static methods are defi ned explicitly with the static keyword. There is one distinction between a static method in a class and an interface. A static method defi ned in an interface is not inherited in any classes that implement the interface. Here are the static interface method rules you need to be familiar with: 1. Like all methods in an interface, a static method is assumed to be public and will not compile if marked as private or protected. 2. 2. To reference the static method, a reference to the name of the interface must be used.
  • 12. Static Method Example public interface Discharge{ static int no_Of_Days_Admit() { return 10; } }
  • 13. Polymorphism Polymorphism is a oops feature in which the property of an object takes on many different forms. No of ways polymorphism achieved: Java object may be accessed using a reference with the same type as the object . Reference that is a superclass of the object, Reference that defi nes an interface the object implements, either directly or through a superclass. Explicit cast is not required if the object is being reassigned to a super type or interface of the object

Editor's Notes

  • #3: Instructor Notes: