what is difference between interface and abstract class..?

Answer Posted / nipun advinder

Interface:
1)In interface you cannot provide any implementations of
any function.
2)you must give implementations for all the methods of an
interface if you implement it in a class
3)cannot have private method
4)Scenario to use it would be to separate out the
implementation from the api

Abstract Class:
1)In interface you can provide implementations of any
function but at least one function should be abstract.
2)you must give implementations for all the abstract
methods of a abstract class if you extend it in a class
3)can have private method
4)Scenario to use it would be to denote is as a generalized
class which could provide some common functionality and you
want that it cannot be instantiated instead more
specialized forms are used.

eg abstract class account
class savingsaccount extends account
class currentaccount extends account

In this scenario assume that class account cannot provide
the complete functionality alone but contain some standard
ones.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does pointer mean?

755


Is array synchronized in java?

803


What is a stringbuilder?

707


What is string pooling concept?

783


What is the difference between hashset and treeset in java?

776


What are thread safe functions?

720


Difference between arraylist and vector.

819


Can we use catch statement for checked exceptions?

754


What is empty string literal in java?

789


What is the default size of load factor in hashing based collection?

810


Under what conditions is an object’s finalize() method invoked by the garbage collector?

789


What is hasnext in java?

777


Explain about static nested classes in java?

819


What is replacefirst in java?

781


Explain the selection sort algorithm?

854