Problem at Constructor's Parameter

Problem:

[sourcecode=’java’]
import java.util.*;
public class Test{
public static void main(String[] args){
ArrayList x = new ArrayList();
x.add(new Student(“Naray”));
x.add(new Student(“Gopal”));

}
}
[/sourcecode]

//in student.java
[sourcecode=’java’]
public class Student {

public Student() {
}

}
[/sourcecode]

Error:
[sourcecode=’java’]
Test.java . 16 cannot find symbol
symbol: constructor Student(java.lang.String)
location: class Student
x.add(new Student(“Naray”)); Test.java . 17 cannot find symbol
symbol: constructor Student(java.lang.String)
location: class Student
x.add(new Student(“Gopal”));
[/sourcecode]
Solution:

make a only string accepting parameter in student constructor

1 thought on “Problem at Constructor's Parameter”

  1. That’s not an ArrayList problem, it’s a problem with your Student class, and you have mis-stated the solution. It is to declare a constructor that takes a single String argument, or better still to only make use of the constructors that do exist instead of inventing one and wondering why you get compilation errors.

Leave a Reply