How to use Keyword Static in Java Tutorial using NetBeans IDE

0
36

This tutorial is all about How to use Keyword Static in Java Tutorial using NetBeans IDE. In this tutorial you will learn how the keyword static. static members belong to the class instead of a specific instance. means that only one instance of a static field exists [1] even if you create a million instances of the class or you don’t create any. It will be shared by all instances.

Since static methods also do not belong to a specific instance, they can’t refer to instance members (how would you know which instance Hello class you want to refer to?). static members can only refer to static members. Instance members can, of course access static members.

So if you have a variable: private staticint i = 0; and you increment it ( i++ ) in one instance, the change will be reflected in all instances

. This tutorial uses NetBeans IDE. Please follow all the steps below to complete this tutorial.

 

How to use Keyword Static in Java Tutorial using NetBeans IDE steps

 

The first step is to

Create your project by clicking file at the top of your project and then click new project, you can name your project whatever you want. After creating a project, you may now create your own class by right clicking the Source Packages and the clicking New Java Class

 

  1.  
  2.  
  3. static String  yourvariable = "";
  4.  
  5. static {
  6.  
  7. yourvariable = "This is the content";
  8.  
  9. }
  10.  
  11. public static void main (String [] args) {
  12.  
  13. System.out.println("The value of your variable is "+yourvariable);
  14.  
  15. }

 

Then you’re done. Run your project and see if it works.

 

 

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: [email protected]

Facebook: facebook.com/RyyanSalem

Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like:

1.) Common String Methods in Java Tutorial using Netbeans IDE
2.) Simple Restaurant Management System using Java

 

 

Facebook Comments
(Visited 45 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here