• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is a class's static members?

 
Ranch Hand
Posts: 424
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is this everything hat is in the class? class variables..methods etc? or is it a sub class within a class?

thanks
 
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static member of any class is a property of class rather than an object i.e., it is common to all the objects.
unlike non static members,objects don't have distinct copy of these members.they are used when you actually
want to define some kind of functionality in a class that will remain equal for all objects of the class in which it
is declared.for ex-suppose you need to count every time a instance of a class is instantiated,you can achieve it
via this by declaring a static variable and increment it each time in a constructor when it is instantiated.they are
also used to define a constant by using a final keyword along with it.static members are accessed via class name
rather than an object.

you can have a static -->
1.variable
2.static nested class
3.static methods
4.static block-they are actually used generally for changing default values of a static variable and are executed when
class will load in JVM.
please see this link for static blocks.
and this one,oracle tutorial,for other static members.

Hope this will help!

kind regards,
Praveen.
 
praveen kumaar
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


i have tried to explain it pictorially.i have used the words "i can talk to other objects" it means if one do some change in it then it will be visible to others.

Thankyou.

kind regards,
Praveen.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

praveen kumaar wrote:. . .static block-they are actually used generally for changing default values of a static variable and are executed when class will load in JVM. . . .

I think you mean static initialisers. They are not easy to understand, and they can cause problems if there are multiple initialisers because multiple initialisers run in a certain order whereas fields are not ordered. They are used for initialising fields, and a single static initialiser is sometimes the best way to initialise your static fields. You can read about them in the Java® Language Specification (=JLS). That part of the JLS is quite easy to understand, unlike this part which tells you that static initialsiers are not members of the class.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can characterize class individuals static utilizing static catchphrase. When we pronounce an individual from a class as static it implies regardless of what number of objects of the class are made, there is one and only duplicate of the static part.
 
praveen kumaar
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi arshi,welcome to ranch!

arshi Bano wrote:We can characterize class individuals static utilizing static catchphrase. When we pronounce an individual from a class as static it implies regardless of what number of objects of the class are made, there is one and only duplicate of the static part.

i don't get you?
can you please elaborate your words(in the last post).

Campbell Ritchie wrote:I think you mean static initialisers.


yeah i mean the same,"static initializers".
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means that there is only ever one of each static member of a class, irrespective of how many or how few instances there are.
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic