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

What are the characteristics of Final,Finally and Finalize keywords.

924


Why is multiple inheritance not supported in java?

767


What is a void in java?

783


Is a method a procedure?

772


What is the purpose of object oriented programming?

709


What is tree node in java?

720


What is difference between equals and hashcode method?

764


Does a function need a return?

733


What is getclass () getname () in java?

877


Is it possible for a yielded thread to get chance for its execution again?

719


What are accessor methods in java?

750


How are the elements of a gridbaglayout organized in java programming?

731


Explain an algorithm to find depth of a binary tree.

787


What is passing by reference in java?

756


What is a protected class in java?

751