IN java collections we have both interfaces and classes.
instead of using interfaces why we can't use classes only
like that why we can't use interfaces only. why we need two
things interface and class.

Answer Posted / sarath

Both of them have different purpose.
A Class have state(Fields) and behaviour(Methods). But in Interface we are telling a common behaviour.
for example I have a class called ABCBycycle.java . It implements some common behaviour of bycyle from Bycycle interface,
by implementing the Bycycle interface we are telling that ABCBycycle.java have some common behaviour of bycyle.
So iterface not the blue print of state and behaviour.
But Class is the blue print of some state and behaviour

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you reverse a link list without using recursion?

599


Define array. Tell me about 2-D array.

589


How do you convert an int to a string in java?

546


Explain a situation where finally block will not be executed?

576


What are methods in java?

541






When should I use stringbuffer?

573


What is java beans?

576


What are computer functions?

482


What is the importance of hashcode() and equals() methods?

583


What are the steps involved to create a bean?

685


What is the use of java?

528


What is the use of set in java?

612


What is variable explain?

528


How much is a java license?

526


What is hashing principle in java?

552