Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java static variable

// A static variable is shared among all objects of a class
class Slogan {
	String phrase; // string description of slogan
    static int count; // slogan count    
    public Slogan(String phrase) {
    	this.phrase = phrase;
        count++;
    }
}

public class SloganCounter {
	public static void main(String[] args) {
    	Slogan slg1 = new Slogan("Live free or die!");
        Slogan slg2 = new Slogan("Don't worry, be happy!");
    
    	System.out.println("Slogans count: " + Slogan.count); 
        // Above outputs: Slogans count: 2
    }
}



Comment

java static variable


Person notReallyAPerson = null;
notReallyAPerson.qtdone++; // this works!

Comment

PREVIOUS NEXT
Code Example
Java :: java break and continue 
Java :: constructor in java 
Java :: java.lang.NoClassDefFoundError: 
Java :: add java 8 support to pom 
Java :: Missing artifact com.sun.jersey:jersey-servlet:jar:1.20-SNAPSHOT 
Java :: How to merge two sorted arrays? 
Java :: crit chance in java 
Java :: framboise bleue ou mure 
Java :: java return new instance of generic type 
Java :: What is the function of an IntentFilter? 
Java :: how to convert infix to postfix and prefix in java 
Java :: android text change java debounce 
Java :: how to covert array into a char 
Java :: video compression with java 
Java :: how to install clojure on linux 
Java :: using a SnackBar on androidstudio 
Java :: java bogosort 
Java :: euclidean algorithm java recursive 
Java :: export java path in ubuntu 
Java :: String Reverse Program in Java. 
Java :: Add an element to ArrayList using addall() method 
Java :: what is delegation in java 
Java :: how to add multiple action listeners java swing 
Java :: A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message) 
Java :: marshalling in java 
Java :: new in t arrray java 
Java :: stream filter java 8 
Java :: selenium java control + enter 
Java :: garbage collection in java 
Java :: Java List Remove Elements using remove() method 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =