Signup as a Tutor

As a tutor you can connect with more than a million students and grow your network.

IT Courses/Java

What is use of interface in Java language?

Asked by Last Modified  

Answer
Follow 0

Please enter your answer

16 Answers   0 Likes | 0 Dislikes

Expert in Java J2EE Training

Polymorphism is one of the key uses of inheritance. For ex, there are many implementations of List interface. Any implementation can be taken as a list object. List list = new ArrayList(), List list2 = new LinkedList etc., This goes to many levels.

Comments
Dislike Bookmark

Software Testing Trainer(Automation)

basically its correct to achieve multiple inheritance ,since its due to abstract method .we use interface to force to use already decided design pattern

Comments
Dislike Bookmark

Java doesn't support multiple inheritance. In terms of interface you can implement that concept because You would be allowed to implement more than one interfaces in one class

Comments
Dislike Bookmark

Join Urbanpro.com, India’s most trusted education portal for your learning requirements

POST YOUR REQUIREMENT NOW

Expert in Java/J2ee technology

In Java 1.8, Interface can contain the default body of a method which is called default method.

Comments
Dislike Bookmark

Interface is used when There only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java.

Comments
Dislike Bookmark

I have more than 9 years of experience in Computer teaching

Interface are used to code re-usability, and they are the real driver of ploymorphism in Java. Interface are also allows multiple inheritance in java.

Comments
Dislike Bookmark

It's like forcing to someone implement this task any how .. java does not support multiple inheritance , if i want to force by abstract class and also extends some other class it is not possible , so we can force it by interface we can also implement multiple interfaces at a time , interfaces have abstract methods which must be implemented by extended class .... usually as a team leader of 15 employees i used to create interface to take surety that every class has same method name.

Comments
Dislike Bookmark

Experienced Software Professional

It is a contract or behaviour which a class that implements that interface must implement. Another use it that it lets Java programs implement "Multiple inheritance of TYPE" which is the ability to implement more than one interface.

Comments
Dislike Bookmark

Data Modeling, MSBI, Sql Server and ETL testing Trainer

An interface in Java has remained a complex topic for many beginners to understand. The first thing which puzzles many programmers is the fact that you cannot define any method inside interface, it a just declaration. By rule, all method inside interface must be abstract (Well, this rule is changing in Java 8 to allow lambda expressions, now interface can have one non-abstract method, also known as a default method). So, if you can't define anything, Why we need an interface? what's the use of an interface, if we are anyway going to write a class and override them to provide behaviour, Can't we declare those methods inside the class itself without using interface etc. Well, if you are thinking in terms of behaviour then you are really missing the point of interface.

Comments
Dislike Bookmark

As you know that Java does not allow multiple inheritance. Sometime in our real life we need to use multiple inheritance for example an amphibious animal inherits the behaviours of Aquatic and Terrestrial animals together, i.e. can walk on land as well as swim in water. To show the relationships in Java we can use Interface, which allows a class to implement more than one interface at a time. Moreover if we want to make all methods as abstract, we can use interface and provide the freedom to end developer to write own definitions for all methods in the implementing (concrete) class.

Comments
Dislike Bookmark
Related Questions

IT Courses/Java

Why we are using this keyword in Java?

Asked by Kiran Bulkquestions 11/07/2017

Answer 7
Follow 5
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

What is the purpose of using throws keyword in java?

Asked by Saritha Bulkquestions 11/07/2017

Answer 10
Follow 8
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

Is synchronized keyword necessary, in Java, if everything that is modified in a function is local to that function?

Asked by Abishiek Bulkquestions 11/07/2017

Answer 5
Follow 1
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

What programming languages should a freshman learn if he already knows C, C++, Java and Python?

Asked by Sushmita Bulkquestions 11/07/2017

Answer 7
Follow 5
Answer submitted successfully. ×

Please enter your answer

IT Courses/Java

What is the use of the "this" keyword in Java?

Asked by Deepak Bulkquestions 11/07/2017

Answer 9
Follow 6
Answer submitted successfully. ×

Please enter your answer

Looking for a Tutor?

Find best Tutors in your locality on UrbanPro.

FIND NOW

Now ask questions in any of the 1500+ Categories, and Get Answers from Tutors on UrbanPro.com

ASK A QUESTION

Related Lessons

Method Overloading vs Method Overriding

1. Method Overloading: Method overloading means a same method with same name can have different implementations/body by changing one of the follwing thing: 1) Number of Parameters 2) Order of Parameters 3) Type of Parameter i. Method overloading can be...

Difference Between Checked And Un-Checked Exception

1. Exception is an abnormal condition in the program, if raises program terminates abnormally. 2. Exception always occurs at runtime only, there is no chance of exception at compile time. 3. Syntactical mistakes or errors are occurs at compile time. 4....

Final, Finally And Finalize In Java

Final: 1. It is a non access modifier that can be applied to variables,methods and to class. 2. Final means non-changable. Final variable: 1. If a variable is declared as final it can't be re-assigned. 2. If there is any final variable in class simply...

Implementation: What Is JPA And JPA?

The basic Java framework to access the database is JDBC. Unfortunately, with JDBC, a lot of hand work is needed to convert a database query result into Java classes. JPA allows us to work with Java classes as it provides a transparent layer to each database...

Why We Should Go With Java?

Java is widely used in the Desktop application, web application, mobile development, games etc. Java is an object-oriented programming language. Its follow all the oops concept Like Object, Class, polymorphism, Inheritance, Encapsulation, Abstraction...

Sponsored

Find Best Java Training Classes?

Find Now »