• 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

que on voodooexam

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is one of the question in voodooexam
Suppose that you make a class file " MyProg . java " . You would like to add a method to this class file such that the method is available to only the subclasses of this class & also to other classes in th same package as the one in which " MyProg . java " is defined .
What access modifier should precede the method name to get such an effect ?
The given ans is protected but my answer is default(no access modifier) so that it can be accessed with the same class/package. what say?
-Sanjana
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you , Ans should be default ,(as it is given by other classes in same package
Happy Preps,
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I don't agree with you.
Because if the access modifier is default you won't
be able to inherit the method from subclasses that
are not in the same package. With protected as an
access modifier you can inherit the method from
a class outside the package.
Gian Franco
 
sanjana narayanan
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gian Franco Casula,

There is no mention abt classes/methods in outisde package. Please read the question again.
-Sanjana
 
Gian Franco
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sanjana,
In the text:

Originally posted by sanjana narayanan:
Suppose that you make a class file " MyProg . java " . You would like to add a method to this class file such that the method is available to only the subclasses of this class & also to other classes in the same package as the one in which " MyProg . java " is defined .


I interpret the text as saying that the method should be available only to
1.) the subclasses of this class
2.) other classes in the same package
So for 1.) it does not say that these should be in the same package.
The text would have been less confusing I guess if it said:
...You would like to add a method to this class file such that the method is available only to other classes in the same package as the
one in which " MyProg.java " is defined and to the subclasses of this class...

What do you think?
Gian Franco
reply
    Bookmark Topic Watch Topic
  • New Topic