Jeremy Hunts Jeremy Hunts - 9 months ago 75
Java Question

Constructor error, setter not working (Java)

I am a java beginner, Why does this code return null ? What is wrong with the constructor ? I set the name yet the sysout returns null.

public class word {

String name;
int frequency;
double rel_freq;

word(String n, int a, double c) {
String name = n;
int frequency = a;
double rel_freq = c;

public static void main(String[] args) {

word maxwell = new word("bobo", 25, 40);


You declare new variables in the constructor instead of using the object variables.
Change it to

word(String n, int a, double c) {