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

Why there is no call by reference in java?

492


Can we extend singleton class?

525


What is the purpose of the main method?

534


Can we sort a map in java?

570


How the interruptible method gets implemented?

548






What is string data?

547


How many ways can you break a singleton class in java?

477


Explain the scope or life time of class variables or static variables?

508


How big is a 32 bit integer?

522


What is JFC?

701


What are the differences between include directive and include action?

534


What is the difference between an interface and an abstract class?

529


What is an example of a keyword?

534


What is fundamental datatype?

519


How many classes can any class inherit java?

500