daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Exception in thread "main" java.lang.StackOverflowError
  2.     at Animal.<init>(Animal.java:54)
  3.     at AnimalState.<init>(AnimalState.java:13)
  4.     at Animal.<init>(Animal.java:54)
  5.     at AnimalState.<init>(AnimalState.java:13)
  6.     at Animal.<init>(Animal.java:54)...
  7.    
  8. import java.time.Duration;
  9.  
  10. public class Save{
  11.  
  12. public static void main(String[] args){
  13.  
  14.     Animal cat = new Animal();
  15.  
  16. }
  17.    
  18. import java.time.Duration;
  19.  
  20. public  class Animal
  21. {
  22. public static  int hoursSinceLastMeal = 3;
  23. public static  int energyPercent = 87;
  24. public static  int age = 7;
  25. public static  boolean isProliferating = false;
  26. public static  boolean isFeedingNewborns = true;
  27. public static  int weight = 3;
  28.  
  29.  
  30. public int getId() {
  31.     return hashCode();
  32. }
  33.  
  34.  
  35. public Animal() {
  36.     new AnimalState( hoursSinceLastMeal, energyPercent, age, isProliferating, isFeedingNewborns, weight );
  37. }
  38.  
  39. }
  40.    
  41. import java.time.Duration;
  42.     import java.util.*;
  43.  
  44.     public class AnimalState extends Animal {
  45.  
  46.     public int hoursSinceLastMeal;
  47.     public int energyPercent;
  48.     public int age;
  49.     public boolean isProliferating;
  50.     public boolean isFeedingNewborns;
  51.     public int weight;
  52.  
  53.     public AnimalState( int hoursSinceLastMeal, int energyPercent, int age,
  54.     boolean isProliferating, boolean isFeedingNewborns, int weight){
  55.  
  56.     this.hoursSinceLastMeal = hoursSinceLastMeal;
  57.     this.energyPercent = energyPercent;
  58.     this.age = age;
  59.     this.isProliferating = isProliferating;
  60.     this.isFeedingNewborns = isFeedingNewborns;
  61.     this.weight = weight;
  62.  
  63.     System.out.println(String.format("%s %s %s %s %s %s",
  64.     hoursSinceLastMeal, energyPercent, age, isProliferating,
  65.     isFeedingNewborns, weight));
  66.     }
  67.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top