Created
February 17, 2016 01:00
-
-
Save zoolu-got-rhythm/a1054ef7f64cf68e3701 to your computer and use it in GitHub Desktop.
This file contains 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
public class Organism{ | |
public Integer lifespan; | |
public int iq; | |
public String species; | |
// base class (super class) | |
public Organism(int lifespan, int iq, String species){ | |
this.lifespan = lifespan; | |
this.iq = iq; | |
this.species = species; | |
} | |
public void summary(){ | |
System.out.println(this.lifespan + "," + this.iq + " " + this.species); | |
} | |
public void age(int n){ | |
if(n < 0) { | |
this.species + " has perished."; | |
} else{ | |
this.lifespan - n; // compiler: "error: not a statement" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://en.wikipedia.org/wiki/Immutability