User Tools

Site Tools


java:variables:global_variable

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

java:variables:global_variable [2024/02/16 01:04] (current)
Line 1: Line 1:
 +====== global variable ======
 +define a global variable in java, after the public class block
  
 +===== example of global varialbe  in java =====
 +<code java>
 + package codereferececomjava;
 +
 +public class CodeRefereceComJava {
 +
 +    public static int globalDigit; // define a global variable
 + 
 +    public static void main(String[] args) {
 +                
 +        int digit = 5; // define and inital a local variable
 +        globalDigit = digit; // initalisize the global variable
 +        
 +        funct(); // call funct();
 +    }
 +
 +    
 +    public static void funct() {
 +        System.out.println(globalDigit); // print out the global variable
 +    }
 +    
 +}
 + 
 +</code>
 +
 +=== output of global variable ===
 +     42

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
java/variables/global_variable.txt · Last modified: 2024/02/16 01:04 (external edit)

Impressum Datenschutz