Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Serverless Applications with Node.js this week in the NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Regarding method overloading and overriding  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Can anybody give me the answer for this question..

1.my question is can we have the same or different access specifiers(like private or public for the methods definition) for the overloading and overriding?

2.can a method overloaded in its subclass ?
 
Sheriff
Posts: 21692
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by h kumar:
1.my question is can we have the same or different access specifiers(like private or public for the methods definition) for the overloading and overriding?


Overloading creates a completely new method that just happens to have the same name. Therefore you can do anything with it - except give it the same parameter list as the overloaded method.

For overriding you can only make a method more public. You can't override private methods (the sub class doesn't know anything about them, you'll redefine them instead), but methods with default access can become protected or public, and protected methods can become public. Public methods can't become protected though.

2.can a method overloaded in its subclass ?


Overloading can happen even in the same class because of what I said before.
[ October 08, 2007: Message edited by: Rob Prime ]
 
h kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
Thanks for your replay, as now i understand bit but still i ahve some doubt regarding overloading

as my question is yesterday i red in a book that we can overload a method in subclass also.. how is it possible ?
 
Java Cowboy
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overloading in a subclass:

Now class Sub has two overloaded versions of method(...): one that takes an int (inherited from Super) and one that takes a String.
 
brevity is the soul of wit - shakepeare. Tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!