Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You must understand the difference between a class and an instance of that class. If you see a car on the street, you know immediately that it's a car even if you can't see which model or type. This is because you compare what you see with the <em>class</em> "car". The class contains which is similar to all cars. Think of it as a template or an idea.</p> <p>At the same time, the car you see is an instance of the class "car" since it has all the properties which you expect: There is someone driving it, it has an engine, wheels.</p> <p>So the class says "all cars have a color" and the instance says "this specific car is red".</p> <p>In the OO world, you define the class and inside the class, you define a field of type <code>Color</code>. When the class is instantiated (when you create a specific instance), memory is reserved for the color and you can give this specific instance a color. Since these attributes are specific, they are non-static.</p> <p>Static fields and methods are shared with all instances. They are for values which are specific to the class and not a specific instance. For methods, this usually are global helper methods (like <code>Integer.parseInt()</code>). For fields, it's usually constants (like car types, i.e. something where you have a limited set which doesn't change often).</p> <p>To solve your problem, you need to instantiate an instance (create an object) of your class so the runtime can reserve memory for the instance (otherwise, different instances would overwrite each other which you don't want).</p> <p>In your case, try this code as a starting block:</p> <pre><code>public static void main (String[] args) { try { MyProgram7 obj = new MyProgram7 (); obj.run (args); } catch (Exception e) { e.printStackTrace (); } } // instance variables here public void run (String[] args) throws Exception { // put your code here } </code></pre> <p>The new <code>main()</code> method creates an instance of the class it contains (sounds strange but since <code>main()</code> is created with the class instead of with the instance, it can do this) and then calls an instance method (<code>run()</code>).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload