Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You would want to use the static modifier on the method you wanted to access. This would mean that in other classes you can access the method using ClassName.methodname(parameters). So for instance if you wanted to have setused be a static method, then you would access it in first by alpha.setUsed:</p> <pre><code>public static void setUsed(int use) { used=use; } public class first { public void main(String args[]) { alpha.setUsed(); } } </code></pre> <p>If you want to find out more about static and other subjects then head to the Java Tutorials (<a href="http://docs.oracle.com/javase/tutorial/" rel="nofollow">http://docs.oracle.com/javase/tutorial/</a>), they are pretty good at explaining it all.</p> <p>You are also initialising 5 objects, not 1. To have the class alpha behave like an array would require you to have alpha extend Array.</p> <pre><code>public alpha extends Array {} </code></pre> <p>This will allow the class to use all the methods of Array via inheritance. Note that another word for inheritance is polymorphism and has been mentioned above.</p> <p>Also, the objects in the array have to be instantiated now that you have initialised them.</p> <pre><code>public void main(String args[]) { alpha[] obj1=new alpha[5]; for(int i-0;i&lt;5;i++) { obj[i] = new alpha(); obj1[i].setused(1); } } </code></pre> <p>Objects have to be initialised (given memory space) and then instantiated (filling the memory space with an actual object).</p> <p>Notice how objects are usually called:</p> <pre><code>alpha a = new alpha(); </code></pre> <p>That is initialisation and instantiation on one line, here it is on two lines:</p> <pre><code>alpha a; a = new alpha(); </code></pre> <p>The first line allocating memory for a, the second actually creating a and placing it in that memory, ready for use.</p> <p>You have only initialised the array of objects, so there would be a NullPointerException when you tried to use them.</p> <p>Hope this helped.</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.
    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