Win a copy of Head First Android this week in the Android 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Overriding

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<code>
consider the following code. Does the method aMethod in subb class override aMethod in the sub class...??? b'coz the return types are different and the argument are also different and the 'Exception' is not a subclass of 'IOException'.The reason why i posted this question is b'coz this compiled or i got my fundamentals of overriding wrong.
would appreciate a reply
---------------------------------------------

import java.io.*;
class sub{
public float aMethod(float a, float b) throws IOException{
return 1.0f;
}
}
class subb extends sub{
public int aMethod(int a, int b) throws Exception{
return 12;
}
}

</code>
[This message has been edited by Arsho, Ayan (edited November 24, 2001).]
[This message has been edited by Arsho, Ayan (edited November 24, 2001).]
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NO there is no overriding here just overloading of aMethod since as you pointed out the argument list and return type are different.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Arsho, Ayan
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for fast reply Val , but just one more question
"Aren't overloaded methods supposed to co-exist in same class??"
Thanks
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instance methods are inherited by subclasses so class subb can be seen as containing both aMethod methods and watching at that class in this way you notice that the method aMethod is overloaded in subb.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic