Advertisement
Guest User

CreateClasses.java

a guest
Nov 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package ClassCreation;
  2.  
  3. public class CreateClasses {
  4.     public static void main(String[] args) {
  5.         ClassA[] array = new ClassA[5];
  6.         array[0] = new ClassA(10, true, "String 1");
  7.         array[1] = new ClassA(20, false, "String 2", 90);
  8.         array[2] = new ClassA(30, true, "String 3");
  9.         array[3] = new ClassA(40, false, "String 4", 40);
  10.         array[4] = new ClassA(50, true, "String 5");
  11.        
  12.         for (int i = 0; i < array.length; i++) {
  13.             System.out.println("Data for ClassA object in index " + i + ": ");
  14.            
  15.             System.out.println("\tBoolean Field: " + array[i].getBooleanField());
  16.             //sets to the opposite of what the boolean field previously was
  17.             array[i].setBooleanField(!array[i].getBooleanField());
  18.             System.out.println("\tNew Boolean Field: " + array[i].getBooleanField());
  19.            
  20.            
  21.             System.out.println("\tInteger Field: " + array[i].getIntegerField());
  22.             //adds 15 to the previous integer field
  23.             array[i].setIntegerField(array[i].getIntegerField() + 15);
  24.             System.out.println("\tNew Integer Field: " + array[i].getIntegerField());
  25.            
  26.            
  27.             System.out.println("\tString Field: " + array[i].getStringField());
  28.             //changes string to "New String" + index of obj
  29.             array[i].setStringField("New String Field " + i);
  30.             System.out.println("\tNew String Field: " + array[i].getStringField());
  31.            
  32.             System.out.println("\n");
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement