• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with super keyword ?  RSS feed

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , i just have a question , which is

with this line my constructor of consdemo class is getting envoked and the value ie. 10 is assigned to size variable .
with this line my constructor of cons class is getting envoked and the value ie. 20 is assigned to size variable which is in parameter and in the body i have called the parent class constructor like so now value 20 is passed to parent class constructor which then sets that value 20 to its size variable with the statement so , when i called the size variable with the reference of consdemo class why i m getting the out put as 10 and not 20.

 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naved momin wrote:

Why do you think it should print 20?

Note that c and c1 point to 2 different instances, and hence each has a copy of 'size' which is independent of each other.
 
Vijay Tidake
Ranch Hand
Posts: 148
Hibernate Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This program gives the right output

in consdemo : 10
in cons : 20

so,whats the problem?
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay Tidake wrote:Hi,

This program gives the right output

in consdemo : 10
in cons : 20

so,whats the problem?

thanks i got that
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!