title: java: non-static variable this cannot be referenced from a static context
body: <p>I have error  java:</p>
  <blockquote>
  <p>non-static variable this cannot be referenced from a static context</p>
  </blockquote>
  <p>when compiling the code in line</p>
  <pre><code>Man m1 = new Man(&quot;a1&quot;, &quot;b1&quot;, 11); 
  </code></pre>
  <p>How to fix that?</p>
  <pre><code>public class Solution
  {
     public static void main(String[] args)
     {
        //create two object of every class here
        Man m1 = new Man(&quot;a1&quot;, &quot;b1&quot;, 11);
        Man m2 = new Man(&quot;a2&quot;, &quot;b2&quot;, 12);
        Woman w1 = new Woman(&quot;a11&quot;, &quot;b11&quot;, 13);
        Woman w2 = new Woman(&quot;a22&quot;, &quot;b22&quot;, 14);
  
         //output them to screen here
         System.out.println(m1.name + &quot; &quot; + m1.age + &quot; &quot; + m1.address);
          System.out.println(m2.name + &quot; &quot; + m2.age + &quot; &quot; + m2.address);
          System.out.println(w1.name + &quot; &quot; + w1.age + &quot; &quot; + w1.address);
          System.out.println(w2.name + &quot; &quot; + w2.age + &quot; &quot; + w2.address);
  }
  
      //add your classes here
      public class Man
      {
          private String name;
          private String address;
          private int age;
  
          public Man(String name, String address, int age)
          {
              this.name = name;
              this.address = address;
              this.age = age;
          }
      }
      }
  }
  </code></pre>
  <p>or more simply (<a href="https://www.mycompiler.io/view/CXnsefOpBM6" rel="nofollow noreferrer">mycompiler.io fiddle</a>)</p>
  <pre><code>class HelloWorld {
  
      public static void main(String[] args) {
          new Tester(&quot;hello&quot;);
      }
      
      class Tester {
          public Tester(String s) { }
      }
  }
  </code></pre>