> > Hello Please help
>
[quoted text clipped - 10 lines]
>
> http://java.sun.com/docs/books/jls/third_edition/html/interfaces.htmlhttp://java
.sun.com/docs/books/jls/third_edition/html/classes.html#8....
Thank you.
But it is not a homework question. I did my own thought and want to
know others opinion.
Here are myown respond are they right??
> >Q 1) Is it possible for an interface class to have no method?
my answer is NO
> > Q 2) Is it possible for an interface class to declare variables only no method?
my answer is NO
> > Q 3) What is the main difference between interface and abstract class?
If you extends more than one interface and did not
implement some methtod then for
these classes you have to name them abstract
> > Q 4) Is it possible to have only abstract class without interface
Based on the above definition my answer is NO
Am I right? or wrong?
-sem
> > class?
Lew - 14 Mar 2007 06:12 GMT
> But it is not a homework question. I did my own thought and want to
> know others opinion.
> Here are myown respond are they right??
>>> Q 1) Is it possible for an interface class to have no method?
> my answer is NO
The correct answer is yes.
>>> Q 2) Is it possible for an interface class to declare variables only no method?
> my answer is NO
Interfaces may not have instance variables at all.
>>> Q 3) What is the main difference between interface and abstract class?
> If you extends more than one interface and did not
> implement some methtod then for
> these classes you have to name them abstract
Not correct. If you /implement/ an interface and don't want to implement all
its methods, the class must be abstract.
But that doesn't explain the difference between interfaces and abstract classes.
The difference between an abstract class and an interface is the difference
between any class and an interface.
An interface is a contract; it defines a type to which implementing classes
must conform, but has no implementation. Method bodies are forbidden. Instance
variables are forbidden.
An abstract class, like any class, is an implementation, possibly of an
interface's contract. It may, and usually does, contain method bodies.
>>> Q 4) Is it possible to have only abstract class without interface
> Based on the above definition my answer is NO
The correct answer is yes.
-- Lew
Lew - 14 Mar 2007 06:21 GMT
> But it is not a homework question. I did my own thought and want to
> know others opinion.
> Here are myown respond are they right??
>>> Q 1) Is it possible for an interface class to have no method?
> my answer is NO
The correct answer is yes.
>>> Q 2) Is it possible for an interface class to declare variables only no
method?
> my answer is NO
The correct answer is yes.
>>> Q 3) What is the main difference between interface and abstract class?
> If you extends more than one interface and did not
> implement some methtod then for
> these classes you have to name them abstract
Not correct. If you /implement/ an interface and don't want to implement all
its methods, the class must be abstract.
But that doesn't explain the difference between interfaces and abstract classes.
The difference between an abstract class and an interface is the difference
between any class and an interface.
An interface is a contract; it defines a type to which implementing classes
must conform, but has no implementation. Method bodies are forbidden. Instance
variables are forbidden.
An abstract class, like any class, is an implementation, possibly of an
interface's contract. It may, and usually does, contain method bodies.
>>> Q 4) Is it possible to have only abstract class without interface
> Based on the above definition my answer is NO
The correct answer is yes.
-- Lew
Sem wrote:
> Hello Please help
> Q 2) Is it possible for an interface class to declare variables only
> no method?
[quoted text clipped - 4 lines]
> Final int books = 50;
> }
"Final" is not a keyword and will cause you grief used in a declaration that
way, even in places where such a declaration would otherwise be permissible.
> Q 4) Is it possible to have only abstract class without interface
> class?
A true devoté if Inversion of Control ("IOC", see the Swing project) might
think of such a class as ronin.
-- Lew