Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Static variables  RSS feed

 
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!