am new to java and i am in the learning phase of core java .i know that
Java doesnt support Multiple Inheritance instead the work around is to use
Interface
but the doubt i have is interface are nothing but empty abstract
methods.when ever i implement those methods in a class i have to write the
method body in the class.. .if interface is just emply methods then what is
the point of having those empty method names under one tag..
i dont know whether my understanding about interface is correct.if not
please correct me and also if possible give me an explanation...
regards
Prejith
Thomas Schodt - 29 Nov 2006 07:28 GMT
> am new to java and i am in the learning phase of core java .i know that
> Java doesnt support Multiple Inheritance instead the work around is to use
> Interface
It is not a workaround,
the way Java implements inheritance / interfaces
has the side effect of
eliminating the classic multiple-inheritance issue.
> but the doubt i have is interface are nothing but empty abstract
> methods.when ever i implement those methods in a class i have to write the
> method body in the class.. .if interface is just emply methods then what is
> the point of having those empty method names under one tag..
An interface is a promise to implement a method with a specific name and
a specific signature.
The beauty when it comes to the classic multiple-inheritance issue is;
two different interfaces used for different purposes
could potentially have a name/signature conflict,
in which case sorting out the mess
is left as an exercise for the person implementing the class.
As Java only allows you to extend one class
there can never be two conflicting implementations.
visionset - 29 Nov 2006 22:54 GMT
> ...if interface is just emply methods then what is
> the point of having those empty method names under one tag..
Declaration, not Tag
I'll give a high level answer, since that is probably best, whilst you read
around more extensively
An interface is a contract or specification, a promise if you like, to
fulfill the documented behaviour of the *Type*. In an interface it is the
documentation that is the most important part, in the same way a
specification does nothing but says alot. The idea is that armed with such
a specification it is then safe to write code that uses these interfaces and
be confident (one hopes) that any such implementation past, present or
future will behave correctly since the writer will have understood the
documentation and implemented the desired behaviour within their concrete
class.
Think how powerful the proliferation of independent governing bodies, the
likes of W3C etc and there far reaching specifications are. Browsers are
written to conform to the spec and you don't need to bother with Firefox or
Opera [1] documentation, you just know they'll do the right thing. Exactly
the same with interfaces.
[1] Oh did I leave out IE ?

Signature
Mike W
Lew - 02 Dec 2006 18:39 GMT
> am new to java and i am in the learning phase of core java .i know that
> Java doesnt support Multiple Inheritance instead the work around is to use
[quoted text clipped - 10 lines]
> regards
> Prejith
Deja vu!
Why is this in two separate threads separated by a day?
- Lew