Static Class Attributes

Lesson 32
Author : Afrixi
Last Updated : October, 2017


Table of Content

Code

Copyclass Song{
     public String title;
     public String artist;
     public static int songCount = 0;

     public Song(String title, String artist){
          this.title = title;
          this.artist = artist;
          songCount++;
     }
}

public class App{
     public static void main(String [] args){
          Song mySong = new Song("Holiday", "Green Day");
          System.out.println(Song.songCount);
     }
}