• 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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: 21558
100
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.
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!