Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

confused with interface....

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
P Priya
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thankx a lot for the replies
Priya
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic