When we will use an Interface and Abstract class?

Answer Posted / sumit sharma

Interface:-> JDK1.5 and above version provide a superb
functionality through interface. That is the main reason
behind using the interface is basically "Interface provide
the loose coupling and also support multiple inheritance".
This is a 100% abstract class. This is also support and
flexible with Polymorphism.
For Example:-
List<String> list = new ArrayList<String>();
Where as List is an interface while ArrayList is an class.


Abstract:-> Abstract class doesn't support multiple
inheritance and if you are creating an any abstract in any
ordinary classes then you must declare abstract. this is
also a major disadvantage of abstract class is that if you
are extend and class or abstract class then you can't extend
any one. Abstract class can't initialize only extended it.
Abstract class may have at least one or more abstract method.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between association, aggregation and inheritance relationships.

557


What is ternary operator in java?

595


What is volatile data type?

551


Can we execute java program without main method?

524


Why stringbuilder is not thread safe?

542






What is a priority queue java?

527


How to compare two strings in java program?

673


What is protected access modifier?

579


Which is better ascii or unicode?

572


What are filterstreams?

614


What is use of map in java?

517


Why synchronization is important?

589


Explain java heap space and garbage collection?

586


Garbage collection in java?

595


What is an escape character in java?

534