- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does Interface consist of in Java
An interface can be defined using the interface keyword. It contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. An interface is primarily used to implement abstraction and it cannot be instantiated.
A program that demonstrates an interface in Java is given as follows:
Example
interface AnimalSound { abstract void sound(); } class CatSound implements AnimalSound { public void sound() { System.out.println("Cat Sound: Meow"); } } class DogSound implements AnimalSound { public void sound() { System.out.println("Dog Sound: Bark"); } } class CowSound implements AnimalSound { public void sound() { System.out.println("Cow Sound: Moo"); } } public class Demo { public static void main(String[] args) { AnimalSound a = new CatSound(); a.sound(); } }
Output
Cat Sound: Meow
- Related Articles
- What does a JavaScript plugin consist of?
- What is garbage? What does garbage consist of?
- What happens if we does not initialize variables of an interface in java?
- What does the interface ICollection do in C#
- What does the interface IEnumerable do in C#?
- What does the interface IList do in C#?
- What does the interface ICloneable do in C#?
- What does the interface IStructuralComparable do in C#?
- What does the interface IStructuralEquatable do in C#?
- What is Runnable interface in Java?
- What is Callable interface in Java?
- What is list interface in Java?
- What happens if a class does not implement all the abstract methods of an interface in java?
- What is Functional Interface in Java 8?
- What is a remote interface in java?

Advertisements