Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ClassCreation;
- public class CreateClasses {
- public static void main(String[] args) {
- ClassA[] array = new ClassA[5];
- array[0] = new ClassA(10, true, "String 1");
- array[1] = new ClassA(20, false, "String 2", 90);
- array[2] = new ClassA(30, true, "String 3");
- array[3] = new ClassA(40, false, "String 4", 40);
- array[4] = new ClassA(50, true, "String 5");
- for (int i = 0; i < array.length; i++) {
- System.out.println("Data for ClassA object in index " + i + ": ");
- System.out.println("\tBoolean Field: " + array[i].getBooleanField());
- //sets to the opposite of what the boolean field previously was
- array[i].setBooleanField(!array[i].getBooleanField());
- System.out.println("\tNew Boolean Field: " + array[i].getBooleanField());
- System.out.println("\tInteger Field: " + array[i].getIntegerField());
- //adds 15 to the previous integer field
- array[i].setIntegerField(array[i].getIntegerField() + 15);
- System.out.println("\tNew Integer Field: " + array[i].getIntegerField());
- System.out.println("\tString Field: " + array[i].getStringField());
- //changes string to "New String" + index of obj
- array[i].setStringField("New String Field " + i);
- System.out.println("\tNew String Field: " + array[i].getStringField());
- System.out.println("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement