File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Ques 14 from parikosh's site Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Ques 14 from parikosh Watch "Ques 14 from parikosh New topic

Ques 14 from parikosh's site

Chaitali Deshpande

Joined: Jan 17, 2001
Posts: 26
how does the following program compile?
how does method f() specified as final in parent class
gets overriden in the child class.

class WF {
private final void f() {
private void g() {
class OP extends WF {
public final void f() {
public void g() {
public class Overriding {
public static void main(String[] args) {
OP op = new OP();
WF wf = op;
Suresh Selvaraj
Ranch Hand

Joined: Nov 14, 2000
Posts: 104
Any method declared with private accessibility can be overridden
by any method with "default - i.e, no access modifier ",
"protected" and "public" accessibility.
The order in which a method can be overridden is :
private --> friendly --> protected --> public
- Suresh Selvaraj
[ ]

Suresh Selvaraj, (author of JQuiz)<br />SCJP2<br /><a href="" target="_blank" rel="nofollow"></a>
David Roberts
Ranch Hand

Joined: Nov 03, 2000
Posts: 142
The answer to your question is: It's not overriden. Because it's private and the sub class has no visibility to a private method of a super class, a new method is created. If it were a protected final method, then a compile error would happen.
- David

David Roberts - SCJP2,MCP
Chaitali Deshpande

Joined: Jan 17, 2001
Posts: 26
Thanks .My problem is solved.
I agree. Here's the link:
subject: Ques 14 from parikosh's site
It's not a secret anymore!