Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static variables

 
rex tony
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




How?
 
Prasun Howlader
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because constructor in class A assign a= 20,b= 30 but in class B that is not happen so default value 10 and 20 print.
[ March 01, 2008: Message edited by: Prasun Howlader ]
 
rex tony
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why the class B doesn't call value of the constructor of class A?
 
Krep Lock
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rex tony:
why the class B doesn't call value of the constructor of class A?


class B does not instantiate an object of class A, so the constructor would never be called. the fields x and y are static, of course, so no instance is necessary when dealing with them as they belong to the class, not any object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic