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

java ranch mock

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a method with no access modifier be overriden by a method marked protected?
Java ranch says it is True.
But I say it is "false".
A method can over ride another method if its access modifier is same or less restrictive than the overriden method.
Some one plz clarify.
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Ranch is right
and so is the statement you made!
protected is LESS restricted the the DEFAULT (no thing written) modifier.
default allows only classes that in the same package to access the method/varuiable.
protected allows all the classes in the same package AND if they inherit from that class.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by pradeep bhat:
Can a method with no access modifier be overriden by a method marked protected?
Java ranch says it is True.
But I say it is "false".
A method can over ride another method if its access modifier is same or less restrictive than the overriden method.
Some one plz clarify.


The method with no modifier is more restrictive than the method marked protected..
e.g.
// supper class
package sample;
public class testObj
{
protected void tstMethod(int i){

}
}
//sub class
package sample;
class tstObj2 extends sample.testObj
{
void tstMethod (int i) {

}

}
error in subclass : access modifier more restrictive.
HTH
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Dark Maul"
Welcome to the JavaRanch! Please adjust your displayed named to match the JavaRanch Naming Policy. As much as we all enjoy Star Wars, please choose one that is not "Obviously fictitious".
You can adjust it here.
Thanks! and welcome to the JavaRanch!
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic