-4
System.out.println("The non pure blood Horses over 2 years old are: ");
if(!pureBlood == false)
{
    System.out.printf("name= %s\nage= %d\nheight= %s\ncolor= %s\n", 
                             this.name, this.age, this.height, this.color);
}

When I compile it I get errors like this

non-static variable this cannot be referenced from a static context 
System.out.printf("name= %s\nage= %d\nheight= %s\ncolor= %s\n", this.name, this.age, this.height, this.color);"
Pshemo
  • 122,468
  • 25
  • 185
  • 269
  • 2
    Can you give us a more specific example of what you want? What output do you expect? Why do you think it isn't working? – Gordonium Feb 23 '15 at 00:31
  • Define "isn't working". – Pshemo Feb 23 '15 at 00:43
  • To add more informations to your question use [edit] option. – Pshemo Feb 23 '15 at 00:43
  • 1
    @LeaTano: You'll lose the +2 suggested edit rep when this question is deleted (which it will be, unless dramatically improved). Consider spending your time improving questions more worthy of being improved, or more bluntly, don't polish turds. – Jeffrey Bosboom Feb 23 '15 at 00:46
  • 1
    Based on your [comment](http://stackoverflow.com/questions/28665212/i-need-to-display-the-information-but-this-isnt-working-why#comment45625291_28665229) (in now deleted answer) it looks like your question is duplicate of: [non-static variable cannot be referenced from a static context](http://stackoverflow.com/q/2559527/1393766) – Pshemo Feb 23 '15 at 01:01
  • @JasonHardison *which* horse's name, age, height and color do you want to print? – user253751 Feb 23 '15 at 01:08

1 Answers1

0

You are trying to refer to your variables (this.name, this.age, ... presumably) within a static method in your code.

If you want to print those attributes, put it in an instance method in your class.

public void toString(){
          System.out.println("The non pure blood Horses over 2 years old are: ");
          if(!pureBlood == false){
          System.out.printf("name= %s\nage= %d\nheight= %s\ncolor= %s\n", 
                               this.name, this.age, this.height, this.color);
          }
    }

Without more of your code I have no idea what you're actually trying to do, so this is just a guess.

edenzik
  • 146
  • 1
  • 4