What is Static Modifier and Class?

There may be times in your program where the class objects need to share information – in such cases you can specify one or more class variable and methods that are shared among the objects. When you declare a method in a class static you do not need an instance of the class.

You can use static methods to access other static members of the class, however, you cannot use the static method to access any non-static variables or methods. A class containing static members is called as a static class. There is no static identifier for the class.

Example:

public Class MyClass{
	public static String prop1;
	public static method1(){
		prop1 = “Hello”;
}
public static void main(String args[]){
		MyClass.prop1 = “Bye”;
MyClass.method1();
}
}	


FAQ Home

 
Printer friendly version of the FAQ-JAVA-What-Is-Static-Modifier-And-Class page


Sponsored links

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
SFTP components for .NET
Add complete SSH and SFTP support to your .NET framework application
Virtual File System SDK
Create your own file systems in Windows and .NET applications
PureCM Software Configuration Management
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!

Advertisement



Free Magazine

Free Magazines
eWeek The essential technology information source for builders of e-business.... subscribe now

Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.