467,879 Members | 1,309 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

Simple doubt... Please help

dmjpro
2GB
look at this example.....

Expand|Select|Wrap|Line Numbers
  1. class InterfaceTest1
  2. {
  3.   void test();
  4. }
  5. class ClassTest1
  6. {
  7.    public void test(){}
  8. }
  9. class ClassTest2 extends ClassTest1 implements Interface
  10. {
  11.    public void test(){} //Method overriden or method implementation?
  12. }
  13.  
How it is posiible ......???

Please explain.

Kind regards,
Dmjpro.
Jun 19 '07 #1
  • viewed: 983
Share:
5 Replies
8TB
look at this example.....

Expand|Select|Wrap|Line Numbers
  1. class InterfaceTest1
  2. {
  3.   void test();
  4. }
  5. class ClassTest1
  6. {
  7.    public void test(){}
  8. }
  9. class ClassTest2 extends ClassTest1 implements Interface
  10. {
  11.    public void test(){} //Method overriden or method implementation?
  12. }
  13.  
How it is posiible ......???

Please explain.

Kind regards,
Dmjpro.
You got your class names and variable names wrong there dj. The method test is overriden of course and also the class satisfies the contract of the interface by implementing the method test as well. Normally this is not done because it's useless. Either you're using an abstract class or an interface. And choice is usually obvious.
Jun 19 '07 #2
dmjpro
2GB
You got your class names and variable names wrong there dj. The method test is overriden of course and also the class satisfies the contract of the interface by implementing the method test as well. Normally this is not done because it's useless. Either you're using an abstract class or an interface. And choice is usually obvious.

Actually what happens to me.
Today I see the Collection interface carefully.
There I see a method int hashCode() and the class which by default extends Object and implements Collection interface or it's sub-interfaces have to implement the method int hashCode().
That's why I questioned it.

Kind regards,
Dmjpro.
Jun 19 '07 #3
8TB
Actually what happens to me.
Today I see the Collection interface carefully.
There I see a method int hashCode() and the class which by default extends Object and implements Collection interface or it's sub-interfaces have to implement the method int hashCode().
That's why I questioned it.

Kind regards,
Dmjpro.
It is important for concrete classes to implement it that's why it was included in that interface.
Jun 19 '07 #4
dmjpro
2GB
It is important for concrete classes to implement it that's why it was included in that interface.
Yup right.
But Object class itself contains int hashCode() method.

Kind regards,
Dmjpro.
Jun 19 '07 #5
Expert 8TB
Actually what happens to me.
Today I see the Collection interface carefully.
There I see a method int hashCode() and the class which by default extends Object and implements Collection interface or it's sub-interfaces have to implement the method int hashCode().
That's why I questioned it.

Kind regards,
Dmjpro.
You don't *have to* implement hashCode() and its compadre equals(), those
methods are just part of the interface to emphasize that you should reimplement
them in several occasions. Read the Collection API docs for those two methods.
And of course, if you don't implement them the interface contract is still fulfilled
because the Object class implements them both (but not the way some collections
expect them to be implemented).

kind regards,

Jos
Jun 19 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

31 posts views Thread by da Vinci | last post: by
138 posts views Thread by ambika | last post: by
6 posts views Thread by Baskar RajaSekharan | last post: by
3 posts views Thread by Baskar RajaSekharan | last post: by
18 posts views Thread by Q. John Chen | last post: by
4 posts views Thread by Christian O'Connell | last post: by
7 posts views Thread by bfowlkes | last post: by
26 posts views Thread by jacob navia | last post: by
122 posts views Thread by ivan | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.