• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

overriding

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the following statement true. if so then why?? Can anyone explain with Eg.

"Each method in a parent class can be overridden at most once in any one subclass"
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think this statment is correct becoz all methods in parent class can not be overriden in subclass , for eg. static & private methods can not be overridden
 
Anju sethi
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry..I meant only public methods, one that can be inherited.

eg.
public class base{
public void check(){
}
}

public class derived1 extends base{
public void check(){
}

}
public class derived2 extends derived1{
public void check(){
}

}

Method check() in derived2 is overidden method or a new Meth in derived2??

I hope i am able to explain my Question now.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Method check() in derived2 is overidden method or a new Meth in derived2??



It is overidden method.

Each method in a parent class can be overridden at most once in any one subclass



This statement is true.
 
Anju sethi
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does dat mean that check() of derived2 is overridden method that is overridding method check() of derived1 and not base.

Can we say check() of derived2 is overidding check() of base???

 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

does dat mean that check() of derived2 is overridden method that is overridding method check() of derived1 and not base.


Yes.

Can we say check() of derived2 is overidding check() of base???


No.
 
Anju sethi
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot
 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just in adition to Amol's post you also can't override static or final members.

Remeber that override are valid only for intance members, as static members are class members they can just be overloaded.
 
reply
    Bookmark Topic Watch Topic
  • New Topic