| Author |
que on voodooexam
|
sanjana narayanan
Ranch Hand
Joined: Nov 25, 2003
Posts: 142
|
|
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
|
 |
Vishy Karl
Ranch Hand
Joined: Sep 08, 2003
Posts: 116
|
|
I agree with you , Ans should be default ,(as it is given by other classes in same package Happy Preps,
|
"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
|
 |
Gian Franco
blacksmith
Ranch Hand
Joined: Dec 16, 2003
Posts: 975
|
|
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
|
"Eppur si muove!"
|
 |
sanjana narayanan
Ranch Hand
Joined: Nov 25, 2003
Posts: 142
|
|
Hi Gian Franco Casula, There is no mention abt classes/methods in outisde package. Please read the question again. -Sanjana
|
 |
Gian Franco
blacksmith
Ranch Hand
Joined: Dec 16, 2003
Posts: 975
|
|
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
|
 |
 |
|
|
subject: que on voodooexam
|
|
|