Q:

Returning an array of strings from a method - java

I have a class
package lab4;

public class CriticalClasses {

    private String course_name;
    private String[] critical_class = new String[3];

    public CriticalClasses (String course){
        course_name = course;
    }

    public CriticalClasses (String class0, String class1, String class2){
      critical_class[0] = class0;
      critical_class[1] = class1;
      critical_class[2] = class2;
    }
    public String toString(){
        return course_name; 
    }
}

this is my main:
package lab4;
import java.util.Scanner;

public class Lab4 {

    public static void main(String[] args) {
    CriticalClasses course;
    course = new CriticalClasses("Ingegneria");
    System.out.println(course);

    CriticalClasses classes;
    classes = new CriticalClasses("number1", "number2","number3");
    //System.out.println(java.util.Arrays.toString(classes));
    //System.out.println(classes); these are comments because i dont know what to write
}

I cannot understand how to return all the inserted values in the main. I should use the toString method, but I can do that only for the element course_name.
Thank you in advance.

A:

Add this method to class CriticalClasses and You will be able to get array of strings
public String[] getCriticalClasses() {
  return critical_class;  
}

if You want just print them in Your main add
System.out.println(classes.getCriticalClasses());

