• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Inherited fields always follow the value of parent?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Base{
int oak=99;
}
public class Doverdale extends Base{
public static void main(String argv[]){
Doverdale d = new Doverdale();
d.amethod();
}
public void amethod(){
//assign new value to inherited int oak, NO IMPACT!
new Doverdale().oak=9;
System.out.println(super.oak);//still 99
System.out.println(this.oak);//follow super.oak value
super.oak=19;
System.out.println(super.oak);//change to 19
System.out.println(this.oak);//Always follow super.oak?!
}
}
The output is
99
99
19
19
I understand that derived class Doverdale has an int field oak with a default value same with that of its parent class. Whenever the super int change its value, the Doverdale int oak will follow.
My question is how we can change the value of Doverdale int without affecting that of its parent class oak. Thanx in advance!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic