Share the Array
| Previous | Home | Next |
Following program for share the array.
/*
* Save as a ShareArray.java
* Program for share the array value.
*/
package r4r.co.in;
class ShareArray {
static int[] arrayValues = new int[8]; // Static array member
ShareArray() {
// Initialization block
for (int i = 0; i < arrayValues.length; i++) {
arrayValues[i] = (int) (100 * Math.random()); //Random value fill into array
}
}
// Listvalues method call by the object
private void ListValues() {
for (int i = 0; i < arrayValues.length; i++) // Value count into Array
{
System.out.print(" " + arrayValues[i]); // Display the Array
}
System.out.println();
}
public static void main(String[] args) {
//First object create.
ShareArray array = new ShareArray();
System.out.println("\n First object Execuited: ");
//Call the ListValue method
array.ListValues();
//Second object create.
ShareArray array1 = new ShareArray();
System.out.println("\n Second object Execuited: ");
array1.ListValues();
//Value from the ListValue method
System.out.println("\n Value inside the Listvalue: ");
array.ListValues();
}
}
First object Execuited:
99 57 90 73 92 27 46 78Second object Execuited:
27 80 79 17 8 85 80 45Value inside the Listvalue:
27 80 79 17 8 85 80 45
| Previous | Home | Next |