Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Statics Question

 
Ranch Hand
Posts: 201
1
Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am confused by this statement, "A static member can call/access only a static member of its own class" (Ganesh & Sharma, 2013, p. 488). Does this mean that a static reference can only call methods in its class or call fields in its class using the name of the class and the dot operator?

Respectfully,

Ted

Reference

Ganesh & Sharma. 2013. OCP Java SE 7 Cert Guide. Apress.
 
Ranch Hand
Posts: 472
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this assume word access directly .
you can access static members of other class use type name and dot and name of types static member. and also you can create instance of class and access non static member of instance
 
Ranch Hand
Posts: 59
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ted North wrote:"A static member can call/access only a static member of its own class" (Ganesh & Sharma, 2013, p. 488). Does this mean that a static reference can only call methods in its class or call fields in its class using the name of the class and the dot operator?



Hi Ted,

If I understand your statement correctly, I'll say this is not the case: Does this mean that a static reference can only call methods in its class or call fields in its class using the name of the class and the dot operator?
Because if it is within the class itself, you won't be needing to use the class name + dot operator. Example:


You can't however, call an instance members from a static reference:

 
Ted North
Ranch Hand
Posts: 201
1
Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sergej Smoljanov wrote:I think this assume word access directly .
you can access static members of other class use type name and dot and name of types static member. and also you can create instance of class and access non static member of instance



Your reply is confusing to me. The last sentence on creating an instance and accessing instance members makes perfect sense to me though!
 
Ted North
Ranch Hand
Posts: 201
1
Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yin Stadfield wrote:

Ted North wrote:"A static member can call/access only a static member of its own class" (Ganesh & Sharma, 2013, p. 488). Does this mean that a static reference can only call methods in its class or call fields in its class using the name of the class and the dot operator?



Hi Ted,

If I understand your statement correctly, I'll say this is not the case: Does this mean that a static reference can only call methods in its class or call fields in its class using the name of the class and the dot operator?
Because if it is within the class itself, you won't be needing to use the class name + dot operator. Example:


You can't however, call an instance members from a static reference:



Interesting reply. Thank-you for thinking about this some with me. I think in your last example with source-code you meant to assign instanceInt1 to staticInt3 to show the compiler error. Also, I think you meant to assign Example1.instanceInt1 to staticInt2 to show a compiler error. I see what you meant though. I forgot about how it is a compiler error to assign a instance variable to a static variable.

In my opinion calling a static member without a reference of any kind, class reference or object reference, is outside of the scope of this question. Unless in the statement in question a 'static member' is a method that calls instance members in its own class or a different class after creating instances of the class so that the instance members can be called from a static context.

Wow, this can become confusing.

Thank-you for the help!

Regards,

Ted
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic