aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes [B] a private final method can be overridden!!!! [/B] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "[B] a private final method can be overridden!!!! [/B]" Watch "[B] a private final method can be overridden!!!! [/B]" New topic
Author

[B] a private final method can be overridden!!!! [/B]

souji nutak
Greenhorn

Joined: Mar 15, 2007
Posts: 8
Can we override a final private method???


class Base
{
final private void amethod(int iBase)
{
System.out.println("Base.amethod");
}
}



class Over extends Base
{
public static void main(String argv[])
{
Over o = new Over();
Base b = new Over();
int iBase=0;
o.amethod(iBase);
}

public void amethod(int iOver)
{
System.out.println("Over.amethod");
}
}
sarika kumar
Greenhorn

Joined: Jan 30, 2007
Posts: 22
Since amethod is a private method of Base class, so no subclass can inherit it.Hence, any subclass of Base can have its own amethod.
Wiyanto Ngasinur
Ranch Hand

Joined: Dec 11, 2006
Posts: 34
private method is not inherited... so it doesn't matter wheter it's final. maybe you should chnage your private method to public ... to get more aproriate error about overriding final method
sarika kumar
Greenhorn

Joined: Jan 30, 2007
Posts: 22
Originally posted by souji nutak:
Can we override a final private method???


class Base
{
final private void amethod(int iBase)
{
System.out.println("Base.amethod");
}
}



class Over extends Base
{
public static void main(String argv[])
{
Over o = new Over();
Base b = new Over();
int iBase=0;
o.amethod(iBase);
}

public void amethod(int iOver)
{
System.out.println("Over.amethod");
}
}


I feel I didnt explain properly. So writing again.
Any private method cannot be inherited. So, there is no question of overridding. Second thing is, since a subclass cannot inherit private method i.e amethod, it can always redefine amethod.
Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
Hi,

private methods wont be visible out side the class definition where it is decalred. So in case of private method, there is no concept of method overriding.
when you called method on a reference , it will chk the method in the object which is assigned to the reference. so that method will be called.
Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
Hi,

private methods wont be visible out side the class definition where it is decalred. So in case of private method, there is no concept of method overriding.
when you called method on a reference , it will chk the method in the object which is assigned to the reference. so that method will be called.
Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
Hi,

private methods wont be visible out side the class definition where it is decalred. So in case of private method, there is no concept of method overriding.
when you called method on a reference , it will chk the method in the object which is assigned to the reference. so that method will be called.
Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
Sorry , i refreshed the page. So it posted two more times
j bande
Greenhorn

Joined: Mar 08, 2007
Posts: 24
hi friends i am new to this thread. i am planning to giv my exam on april 12. but i don't have links for mock exams or any dumps. can anyone help me in this regard...............
sadasiva kumar
Ranch Hand

Joined: Oct 30, 2003
Posts: 91
HI bande,
You can get some best mock exams here
Free Mock Exams :http://www.javabeat.net/javabeat/scjp2/index.php





regards
SADASIVAKUMAR UTTI
SCJP1.4


SADASIVAKUMAR UTTI, SCJP1.4
A bend in the road is not the end of the road ... unless you fail to make the turn.
sadasiva kumar
Ranch Hand

Joined: Oct 30, 2003
Posts: 91
Can we override a final private method???


class Base
{
final private void amethod(int iBase)
{
System.out.println("Base.amethod");
}
}



class Over extends Base
{
public static void main(String argv[])
{
Over o = new Over();
Base b = new Over();
int iBase=0;
o.amethod(iBase);
}

public void amethod(int iOver)
{
System.out.println("Over.amethod");
}
}


private methods are not inherited by subclasses and, therefore, cannot be overridden (i.e., all private methods are implicitly final).


regards
SADASIVAKUMAR UTTI
SCJP1.4
j bande
Greenhorn

Joined: Mar 08, 2007
Posts: 24
hi sadasiva kumar, thanks for your kind reply.
[ March 19, 2007: Message edited by: j bande ]
 
 
subject: [B] a private final method can be overridden!!!! [/B]