Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static : Bug in K&B P-145

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At Page 145 (K& B book)

So, the way we access a static method (or static variable) is to use the dot operator on the class name, as opposed to using it on a reference to an instance.

 
Vishal K Patel
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static members can be accessed by the [instanse_name.static_member].

Neither compiler nor JVM complains about this.
But the resul remains same whether one use class name or instanse name.
 
Matt Russell
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the bottom of that page, K&B say, "the Java language also allows you to use an object reference to access a static member".
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi cowboys,

this isn't a bug. One sentence before, it is said that
But this approach (using a reference to an object) isn't appropriate for accessing a static method, (...)


Yours,
Bu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic