I would recommend couple of changes
1. on case 2, re initialize the object using
Numbers (int size)
method
case 2:
System.out.println("Enter the new size of array: ");
int x = scan.nextInt();
obj = new Numbers(x);
break;
2. move
Numbers obj = new Numbers();
outside the
while
loop to prevent it from being overwritten each time user make a selection
3. You night also need to update
Numbers (int size)
method to include code to initialize the array
Example:
Online Java Compiler - Online Java Editor - Java Code Online - Online Java Runner[
^] - make sure to use interactive mode to run the example.