• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Overriden queston

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a public method be overriden by protected method?
Please explain with example. getting confused..
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dinesh,

You can increase the visibility of a member through overriding, but you can't decrease it. So you can declare the subclass's overridden member public when the parent method is protected, but not vice versa.
 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just to help you look at this example:


 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An "overridden question" occurs when a rancher posts a question underneath a topic that began with a different question. Then when other ranchers read the thread, they will be inclined to respond to the most recent post.

(Sorry. I haven't had coffee yet. :roll: )
 
Ivan Ivanic
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dinesh Tahiliani:
Can a public method be overriden by protected method?
Please explain with example. getting confused..



Dinesh,
It took you 31 minutes to get a reply to this question.
I'm sure some more time elapsed before you had a chance to notice that someone had replied to it.

How long do you think it would have taken to write and compile two small classes to find this out on your own?
 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ivanic,
I nyour program you override the method which was having access modifier public and now it is protected.
As far i know the protected variable is accessible in same package but also the subclass of other package which you have done in your prog.
Correct me if i am wrong..


[BPSouther: Added newlines to narrow this thread a bit]
[ May 06, 2008: Message edited by: Ben Souther ]
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dinesh,

The moderators here are really trying to help you! When Ben asks you to write your own code to test this question it's because that is ABSOLUTELY the best way for you to learn this stuff

It seems that you're not comfortable writing your own Java programs to test stuff out. You really have to make a shift and get used to compiling and running code from the command line. Everyone who scores well on these exams studies by writing and testing a lot of code. The compiler and the JVM are your friends, and compiler errors are your friends too!

We will be thrilled to see you post some code and some error messages and ask what's going on!

hth,

Bert
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic