Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

static int java

// A static variable is shared among all instances of a class
// In example below, Slogan class has a static variable called
// count that was used to count the number of Slogan objects created.
public class Main {
	public static void main(String[] args) {
		Slogan slg1 = new Slogan("Talk is cheap");
		Slogan slg2 = new Slogan("Live free or die");
		System.out.println(Slogan.getCount());}
}
class Slogan {
	private String phrase;
  	// Only one copy of variable count is created
    // And it would be shared among all Slogan objects
	private static int count = 0;
	public Slogan(String phrase) {
		this.phrase = phrase;
		count++;}
	public static int getCount() {
		return count;}
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to check whether a character is alphabet or not in java 
Java :: empty array java 
Java :: java iso 8601 format 
Java :: string to hexstring In java 
Java :: java Modulo 10^9+7 (1000000007) 
Java :: ! en java 
Java :: java send request 
Java :: java terminal colors 
Java :: how to get key value from json object in java 
Java :: android studio breakpoint not working 
Java :: java text file to arraylist 
Java :: java get date in utc 
Java :: java singleton implementation 
Java :: Who made java ? 
Java :: caused by: java.lang.noclassdeffounderror: org/springframework/boot/configurationprocessor/json/jsonexception 
Java :: java syntax for object creation 
Java :: charcodeat java 
Java :: how to print an array in java 
Java :: Hourglass Java 
Java :: java collapse string array 
Java :: java button size 
Java :: loop through an arraylist android studio 
Java :: milliseconds to seconds java 
Java :: create java gui intellij 
Java :: timestamp with zone java 
Java :: how to remove null values in java 
Java :: load a list from text file java 
Java :: java delete column from csv 
Java :: initialize applet in java 
Java :: java split string array 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =