Skip to main content

Posts

Showing posts from December, 2022

Featured Post

Top 10 Advance Java Interview questions?

Top 10 Advance Java Interview questions?   What are the differences between abstract classes and interfaces in Java? What is the difference between ArrayList and LinkedList in Java? What is the purpose of the finalize() method in Java? What is polymorphism in Java and how is it achieved? What are the different types of inner classes in Java? What is the difference between static and non-static methods in Java? What are the different types of exceptions in Java and how do they differ? What is the difference between checked and unchecked exceptions in Java? How does Java handle multithreading and synchronization? What are the different types of JDBC drivers in Java and how do they differ?

What is Interface in Java?

What is Interface in Java?  Interface: An Interface has 3 meanings.  • It is an intermediate between the service and the consumer. • It is also called a 100% abstract class.  • It is also called a rules repository or coding contract.  Programmatically, we create an interface by using a keyword interface. All the methods in an interface are automatically public and abstract. The interface cannot have Constructors and instance variables. Why use Java interface? There are mainly three reasons to use an interface.  They are given below. o It is used to achieve abstraction. o By interface, we can support the functionality of multiple inheritances.  It can be used to achieve loose coupling. How to declare an interface?  An interface is declared by using the interface keyword. It provides total abstraction; which means all the methods in an interface are declared with the empty body, and all the fields are public, static and final by default. A class that i...