Created
September 29, 2014 20:41
-
-
Save OlgaKulikova/6115cf97d369856fffd4 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.Module2.Lesson1.task2; | |
public class MyClass { | |
public static void main(String[] args) { | |
for (int i = 0; i < 10; i++) { | |
MyObject object = new MyObject(); | |
} | |
System.out.println("У меня всего " + MyObject.getCount() + " объектов."); | |
} | |
} |
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.Module2.Lesson1.task2; | |
/* | |
Написать класс, который умеет считать количество созданных объектов этого класса (static). | |
*/ | |
public class MyObject { | |
private static int count; | |
public MyObject() { | |
count++; | |
} | |
public static int getCount() { | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment