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

Can we use a default constructor of a class even if an explicit constructor is defined?

871


What is a file pointer?

730


When we serialize an object does the serialization mechanism saves its references too?

751


What are the advantages and disadvantages of object cloning?

804


What is the use of default method in interface in java?

792


what is the significance of listiterator in java?

835


How to print an arraylist in java?

772


Does list allow duplicates in java?

713


What are the default and parameterized constructors?

825


Differece between class and generic class?

810


Difference between current previous versions of Java?

806


How many bits is a 64 bit byte?

769


What are inbuilt functions in java?

812


What are the advantages of autoboxing?

770


What is the size of int?

864