Learn COBOL from the Best Tutors
Search in
In Java, an interface is a blueprint of a class that defines a set of methods (and constants) that other classes must implement. It establishes a contract for what methods a class should contain without specifying the implementation details.
Interfaces declare methods without providing their definitions; they only contain method signatures (method name, parameters, return type) and constant declarations. Any class that implements an interface must provide concrete implementations for all the methods defined in the interface.
This concept enables multiple classes to adhere to a specific interface while implementing methods in their unique way. It promotes code reusability, allows for multiple inheritances (as Java doesn't support multiple class inheritance), and facilitates polymorphism by allowing different objects to be treated through a common interface.
For example, an interface Shape
might declare methods like calculateArea()
and draw()
. Different classes such as Circle
, Square
, and Triangle
can implement the Shape
interface with their respective implementations of these methods while ensuring they adhere to the contract specified by the interface.
The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not the method body. It is used to achieve abstraction and multiple inheritances in Java using Interface. In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method body. Java Interface also represents the IS-A relationship.
When we decide on a type of entity by its behavior and not via attribute we should define it as an interface.
read lessView 1 more Answers
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Make a Career as a BPO Professional
Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...
Learn Hadoop and Big Data
Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...
Learn Microsoft Excel
Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...
Make a Career in Mobile Application Programming
Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...
Looking for COBOL Training?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for COBOL Classes are on UrbanPro
The best Tutors for COBOL Classes are on UrbanPro