• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
}
}
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry , i refreshed the page. So it posted two more times
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...............
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
sadasiva kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sadasiva kumar, thanks for your kind reply.
[ March 19, 2007: Message edited by: j bande ]
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic