File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes confused with interface.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "confused with interface...." Watch "confused with interface...." New topic
Author

confused with interface....

P Priya
Greenhorn

Joined: Dec 05, 2000
Posts: 5
hi
i'm a bit confused with a lot of questions.can anyone one help me out.
what is the difference between an interface and an abstract class.
and why is an interface used in the first place?
and what does this implementation mean actually.please explain.
can we implement more than one interface ,if so howmany?
Thankx in advance
Priya
Brett Knapik
Ranch Hand

Joined: Oct 15, 2000
Posts: 255
in interfaces you cannot define anything you can only create the basics and you must override everything you wish to use in the extending class. In an abstrct class you can define certain things. I believe you can do more by saying (however i am not possitive)
public class dog extends animal implements runable, forest, earth
hope this helps
------------------
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
GIRISH L
Greenhorn

Joined: Dec 05, 2000
Posts: 6
Originally posted by P Priya:
hi
i'm a bit confused with a lot of questions.can anyone one help me out.
what is the difference between an interface and an abstract class.
and why is an interface used in the first place?
and what does this implementation mean actually.please explain.
can we implement more than one interface ,if so howmany?
Thankx in advance
Priya

in an interface all the methods are abstract where as an abstract
class may or may not have an abstract method
since java doesnt have multiple inheritance as in c++
interfaces are provided and they have to be implemented remember not extended
any number of interfaces can be implemented
hope this helps and is right
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Please read and follow the Naming Policy. It's to your benefit. We periodically do book give aways to people who post to a forum and as a matter of fact one is being conducted on the Advanced forum now. Only those who meet the naming policy are entered in the contest for the give away so....


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Mythri Vaths
Greenhorn

Joined: Nov 29, 2000
Posts: 4
hi ,
an abstract class is one which has abstract methods(methods with no definition) and can also have other methods(methods with definition).
an interface is a pure abstract class wherein u have only abstract methods.
java does not support multiple inheritance directly but it supports multiple inheritance indirectly through interfaces. hence the need for interface.
we can extend any number of interfaces .
eg. if a is a class and b,c,d are interfaces then the following is possible:
public class try extends a implements b,c,d
note: an interface can also extend another interface
hope this helps

------------------
regards,
mythri
[This message has been edited by Mythri Vaths (edited December 06, 2000).]
[This message has been edited by Mythri Vaths (edited December 06, 2000).]


regards,<BR> mythri
P Priya
Greenhorn

Joined: Dec 05, 2000
Posts: 5
thankx a lot all of u guys out there.
the information was very helpful.
i've one more doubt,is it true that an interface is a collection? if yes,can u please explain.
As far as i know ,collections are like vectors or arrays.correct me if i'm wrong.
thankx again all of u
Priya
P Priya
Greenhorn

Joined: Dec 05, 2000
Posts: 5
thankx a lot for the replies
Priya
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
There is also some discussion of interfaces in another thread
http://www.javaranch.com/ubb/Forum33/HTML/000972.html . You might want to look there and see if it helps.
You ask "is it true that an interface is a collection?". The answer has to be no. Collection is an interface, but an interface is just a definition of which methods a class must implement in order to be considered as and instance of that interface.
Consider the interface:

This just states that if a class wishes to claim that it implements Getter, it must provide a method public String get(). So the first class below will compile, and the second onw won't.

Has this helped?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confused with interface....