posted 17 years ago
In a super class given method
public void aMethod(){}
In a subclass giving the only visibility is
public void aMethid(){}
Like that,
In a Super class,a method with protected---subclass,a method with protected/public is valid.giving private or default is error
In a Super class,a method with private--no overriding in subclass
In a Super class,a method with default-subclass,a method with protected/public/default is valid. giving private is error
I checked every of the above with my compiler.still I need to confirm from anyone because consider the following question.
Given the code below,and making no other changes,which access modifiers ar placed before myMethod() on line 3
class Super{
void myMethod(){//line 3
}
}
class Q extends Super{
void myMethod(){//line 7
}
}
Given options:
1.public
2.protected
3.private
4.none of the above
Given 1,2,3 answers are correct.since private feature is accessible only to its own class,selecting private is also valid.
But my answer is only giving private on line 3 would work.of course ,line 7 is not overridint the super class method.that is a separate method.How come giving public/protected on line 3 is valid for the above program.please help me and correct me if my beginning rules are not correct.