jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java ranch mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java ranch mock " Watch "java ranch mock " New topic
Author

java ranch mock

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8903

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.


Groovy
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
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.
Raj Hans
Greenhorn

Joined: May 10, 2002
Posts: 5
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
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

"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

Joined: Feb 27, 2002
Posts: 8903

Thanks everybody!
 
Don't get me started about those stupid light bulbs.
 
subject: java ranch mock
 
Similar Threads
Overriding
Private methods in super class
Problem with Ques. #120
finalize() chaining?
Java Rule Round-up Error?