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.

Answers were Sorted based on User's Feedback



IN java collections we have both interfaces and classes. instead of using interfaces why we can..

Answer / vanaja

Java doesn't support multiple inheritance.We achieve
multiple inheritance using interface concept.A class can
have only one super class and number of interface.And more
over interface has only abstract methods. We need a sub
class to implement it.We cannot create an object for an
interface. So we cannot use only the classes or only the
interfaces in java.

Is This Answer Correct ?    19 Yes 1 No

IN java collections we have both interfaces and classes. instead of using interfaces why we can..

Answer / reddy

The purpose of interface is to have abstract methods and
the class which implemnts the interface has to define the
methods in the interface.
The reason why java collections have both interfaces and
classes is interface will have common methods which will be
needed by one or many classes. The classes which wants to
behave like this interface will implement this interface
and define methods in the interface.

Is This Answer Correct ?    14 Yes 4 No

IN java collections we have both interfaces and classes. instead of using interfaces why we can..

Answer / easwar

Java doesn't support multiple inheritance.We achieve
multiple inheritance using interface concept.A class can
have only one super class and number of interface.And more
over interface has only abstract methods. We need a sub
class to implement it.We cannot create an object for an
interface. So we cannot use only the classes or only the
interfaces in java.

Is This Answer Correct ?    0 Yes 0 No

IN java collections we have both interfaces and classes. instead of using interfaces why we can..

Answer / 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

IN java collections we have both interfaces and classes. instead of using interfaces why we can..

Answer / shaik baji

Interface in the sence a generic templet that means it will
define a generic functionalities of a group.
For Ex:- We can say "Car" as an interface

1)let's asume if you want a List interface functionalities
the your class should implements the List interface, that
means you should implement all the methods which are
available in List interface even you are not using all the
methods so that the Java developers designed the classes
which are implements the java.util interfaces.

Now if you want any interface functionalities then you just
create an object of that related java.utill package class
and call the methods by using the object.

2)Java doesn't support multiple inheritance.We achieve
multiple inheritance using interface concept.A class can
have only one super class and number of interface.

Is This Answer Correct ?    3 Yes 4 No

IN java collections we have both interfaces and classes. instead of using interfaces why we can..

Answer / rajesh r

In a word to achieve Polymorphism

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More Core Java Interview Questions

How do you trim a space in java?

0 Answers  


Is static variable stored in heap?

0 Answers  


can u give one sinario when you use Abstract Class and When you use Interface.

5 Answers   ITC Infotech,


What are the wrapped, classes?

0 Answers  


Explain the differences between abstraction and encapsulation?

0 Answers  


I have a String s = java; What is the output when I say s.replaceAll('j', 'k'); Also what is the value of s after replacing?

8 Answers   KPIT,


What do you mean by inner class in java? Explain

0 Answers  


Can we override singleton class?

0 Answers  


please tell me what is wrapper class in java with example ?

6 Answers   HP,


What are the different data types in java?

0 Answers  


What is anagram number?

0 Answers  


How do you initialize an arraylist in java?

0 Answers  


Categories