0

I am trying to write a code where the object of a class has an array in it's parameter. I have written the parameterized constructor like as follows -

public abstract class StudentHS {

private String firstName;
private String lastName;
private String rollNumber;
public int[] marksAcquired;
public int hundreds;

// constructor
public StudentHS (String first, String last, String roll, int[] marks) {

    firstName = first;
    lastName = last;
    rollNumber = roll;
    marksAcquired = marks;

}

Now, when I am trying to initialize an object of this class in an array of objects, I am getting an error that says that the constructor is undefined.

public class ResultSystemTest {

public static void main(String[] args) {
    StudentHS studentArts[] = new StudentHS[3];
    StudentHS studentCommerce[] = new StudentHS[3];
    StudentHS studentScience[] = new StudentHS[3];

    studentArts[ 0 ] = new StudentArts("Priyanka", "Ray", "01", {56, 59, 61, 72, 65, 63, 58});
}

StudentArts, StudentCommerce and StudentScience are subclasses of StudentHS here.

Where am I going wrong here?

2
  • This notation {56, 59, 61, 72, 65, 63, 58} can only be used as part of a declaration and initialization. Commented Jun 7, 2015 at 16:10
  • where you initialize the array use new int {56, 59, 61, 72, 65, 63, 58} Commented Jun 7, 2015 at 16:11

1 Answer 1

1

You have to define its type while passing like

 studentArts[ 0 ] = new StudentArts("Priyanka", "Ray", "01", new int[]{56, 59, 61, 72, 65, 63, 58});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.