/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
System.
out.
println("Instanciando ClasseA..."); ClasseA a = new ClasseA();
System.
out.
println("No. de instancias: " + ClasseA.
getNumberInstances());
System.
out.
println("Instanciando ClasseB..."); ClasseB b = new ClasseB();
System.
out.
println("No. de instancias: " + ClasseA.
getNumberInstances());
System.
out.
println("Instanciando ClasseC..."); ClasseC c = new ClasseC();
System.
out.
println("No. de instancias: " + ClasseA.
getNumberInstances()); }
}
class ClasseA {
private static int instances = 0;
public ClasseA() {
instances++;
}
public static int getNumberInstances(){
return instances;
}
}
class ClasseB extends ClasseA {
}
class ClasseC extends ClasseA{
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCVN5c3RlbS5vdXQucHJpbnRsbigiSW5zdGFuY2lhbmRvIENsYXNzZUEuLi4iKTsKCQlDbGFzc2VBIGEgPSBuZXcgQ2xhc3NlQSgpOwoJCVN5c3RlbS5vdXQucHJpbnRsbigiTm8uIGRlIGluc3RhbmNpYXM6ICIgKyBDbGFzc2VBLmdldE51bWJlckluc3RhbmNlcygpKTsKCQkKCQlTeXN0ZW0ub3V0LnByaW50bG4oIkluc3RhbmNpYW5kbyBDbGFzc2VCLi4uIik7CgkJQ2xhc3NlQiBiID0gbmV3IENsYXNzZUIoKTsKCQlTeX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