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 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."
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
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....
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).]
Joined: Dec 05, 2000
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
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.