Last active
December 19, 2021 10:19
-
-
Save sunmeat/f1bc73cfc5928cb4a7c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.alex.static; | |
class Monster { | |
private static int count; | |
private int health; | |
private int attack; | |
public Monster() throws Exception { | |
if (count >= 1) { | |
throw new Exception("oops!"); | |
} | |
count++; | |
System.out.println("monster #" + count); | |
} | |
public static int getCount() { | |
return count; | |
} | |
} | |
public class Program { | |
public static void main(String[] args) throws Exception { | |
// System.out.println(Monster.count); | |
// Monster.count = 5; | |
System.out.println(Monster.getCount()); | |
Monster m = new Monster(); | |
System.out.println(Monster.getCount()); | |
Monster m2 = new Monster(); | |
System.out.println(Monster.getCount()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment