Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clases and their methods?

 
Ahmer Arman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java Friends,
If I declare any class static then what their methods will behave. do they behave like static methods or else.

------------------
Ahmer Arman
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmer
The only type of clas you can declare as static is a nested class. A static inner class can be considered the same as a normal class so the methods in the class would be uneffected by the static modifier. Except that they would not be able to access member variables of the enclosing class because the class they are part of is a static member. In a sense it is like making all of the static inner classes methods static. But is becasue of the nature of the iner class not becasue of the static modifier on the class itself. Although it is due tot he static modifier that the class is static...
hope that helps

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
Bill Siggelkow
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot declare a class to be static -- only methods and variables.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill, as mentioned by Dave, you can declare an inner class as static.
------------------
Bosun
SCJP for the Java� 2 Platform
 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never argue with the bartender, those chipped glasses don't always go straight to the trash can.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic