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

a class can only have static fields?

 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a class can only have static fields ??? if yes then please tell me why is it so ???

like this one

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html
 
fred rosenberger
lowercase baba
Bartender
Posts: 12149
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea where you got that idea from, but it is 100% not true. If it could only have "static" fields, why would you need to call them "static" - they'd just be fields.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:I have no idea where you got that idea from, but it is 100% not true. If it could only have "static" fields, why would you need to call them "static" - they'd just be fields.



actually i was working on Thread class .. i noticed that .. on clicking at " PREV CLASS " on that page (link given above) it appears that many classes provided by java system have static fields .. so i asked
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same logic: I saw a black dog the other day, so all dogs must be black.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Same logic: I saw a black dog the other day, so all dogs must be black.


i think my question was a very stupid one ................ sorry
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, just pointing out the flaw in your logic. One or two examples is not enough to draw such conclusions on.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:No, just pointing out the flaw in your logic. One or two examples is not enough to draw such conclusions on.




Oh I think I misunderstood, thanks for clarifying this for me
 
fred rosenberger
lowercase baba
Bartender
Posts: 12149
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you would be amazed at how many times everyone here at some point drew a conclusion, only a day/week/month later go "What the heck was I THINKING?". In fact, that is why my forehead is so flat - i keep smacking it each time I realize something that should have been obvious.

Don't worry about asking questions - that's what this site is all about.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49460
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a language error. It should read "Can a class have only static fields?" to which the answer is yes. And I don't think people ought to have made fun of you about that mistake.

Go into your Java™ installation folder and find a file called src.zip. Unzip that, and find the "java" folder and inside that the "lang" folder and inside that the "Math.java" file. Explore that file and you can see how it is done.

You can call that a utility class.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:In fact, that is why my forehead is so flat - i keep smacking it each time I realize something that should have been obvious.

For me, it's the side of my head -- from smacking it against the wall.

Seriously, no one is making fun of anyone. Learning from mistakes is sometimes the best learning.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49460
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies then. I can get a bit sensitive about that sort of thing sometimes.
 
khekhone yvan
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe
he wnat to say
a static class has to static fields
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
khekhone yvan wrote:maybe
he wnat to say
a static class has to static fields


i think i would like to say ........."please give me name of a class having non- static fields in java system , if any ".
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Go into your Java™ installation folder and find a file called src.zip. Unzip that, and find the "java" folder and inside that the "lang" folder and inside that the "Math.java" file. Explore that file and you can see how it is done.
.


right now following your instructions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic