1 / 6

Class ArrayTest contains main() method declare array a[5] declare array b[5]

Class ArrayTest contains main() method declare array a[5] declare array b[5] initialize both array with data invoke method addArray () collect the array return by this method print the returned array by invoking printArray () method. Class ArrayMethod addArray(array 1, array 2)

mateja
Download Presentation

Class ArrayTest contains main() method declare array a[5] declare array b[5]

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class ArrayTest contains main() method declare array a[5] declare array b[5] initialize both array with data invoke method addArray() collect the array return by this method print the returned array by invoking printArray() method Class ArrayMethod addArray(array 1, array 2) adds array 1 and array 2 returns an array printArray(array) prints array returns nothing Programming Problem: Passing and Returning Array to/from a Method Write Java code to define the class “ClassArrayMethod”. Then use the methods of this class in the driver class “ClassArrayTest” according to the specifications given below:

  2. Difference Between Class Variables and Instance Variables Source: Ivor Horton, Beginning Java™ 2, JDK™ 5 Edition, Wiley Publishing, Inc.

  3. Controlling Access to Class Members Source: Ivor Horton, Beginning Java™ 2, JDK™ 5 Edition, Wiley Publishing, Inc.

  4. Controlling Access to Class Members Source: Ivor Horton, Beginning Java™ 2, JDK™ 5 Edition, Wiley Publishing, Inc.

  5. Controlling Access to Class Members Source: Ivor Horton, Beginning Java™ 2, JDK™ 5 Edition, Wiley Publishing, Inc.

  6. publicclassObjectData { int [] data; publicObjectData(inti){ data = newint[i]; for (int j=0;j<i;j++) data[j]=j; }//end of constructor }//end of class data Example: Passing Object to a Method Returning Object from a Method publicclassObjectMethod { publicObjectDatasortData(ObjectData ob){ int [] a = newint[ob.data.length]; inti = 0; for(int j=(ob.data.length-1);j>=0;j--){ a[i]=ob.data[j]; i++; }// end of for ob.data = a; return ob; }//end of sortData }//end of class publicclassTestObjectMethod { publicstaticvoid main(String[] args) { ObjectData ob1, ob2; ObjectMethod ob3; ob3 = newObjectMethod(); ob1 = newObjectData(6); ob2 = ob3.sortData(ob1); for(inti=0;i<ob2.data.length;i++){ System.out.println(ob2.data[i]); }// end of for }//end of main() }//end of class

More Related