• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

confusion

 
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//let



some points:
1.changes in variable "a" means state of an object changes.
2."a" is private so it is not inherited by B.

my Que. is : when "a" changes state of which object's gets changed actually...???as it is not a instance variable of B type,, and there is only one object on heap of B..


i m new to java so please try to help me to learn this language......

[Edit - added code tags - MB]
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a isn't visible by B, but it is inherited by B. The object that gets instantiated will contain an int member variable, and that gets changed.

And welcome to the Ranch!
 
Kkush Garg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you mean private members are inherited but not accessible by subclasses....???
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private variables are only accessible inside the class they are declared but Object of B is essentially Object of A and if A changed B automatically changed.
 
Greenhorn
Posts: 15
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't it because the VM actually creates three objects on the heap that to certain extent live autonomous lifes ?
 
Kkush Garg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all......
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic