fork download
  1. class ejemplo2{
  2. static int total;
  3. ejemplo2(){
  4. total++;
  5. }
  6. int getTotal(){
  7. return total;
  8. }
  9. public static void main(String[] args){
  10. ejemplo2 a=new ejemplo2();
  11. ejemplo2 b=new ejemplo2();
  12. ejemplo2 c=new ejemplo2();
  13. System.out.println("Se han declarado: "+a.getTotal()+"objetos");
  14. }
  15. }
Success #stdin #stdout 0.08s 212416KB
stdin
Standard input is empty
stdout
Se han declarado: 3objetos