BASIC - Cant access variables defined in another public Class from same src folder

Answered

Hi,

I'm just getting started with some examples in Java, and I can't find the reason why some variables from a public class cannot be accessed from another one under the same src folder. Even though the variables and constructors seem to have been properly, I just can't use them...

Example: I defined Class 'Main' and Class 'Car' (using the same data as in the training course I got).

Under 'Car' I have:

import java.awt.*;

public class Car {

double averageMilesPerGallon;
String licensePlate;
Color paintColor;
boolean areTailingWorking;

public Car(double inputAverageMPG,
String inputLicensePlate,
Color inputPaintColor,
boolean inputAreTaillightsWorking) {
this.averageMilesPerGallon = inputAverageMPG;
this.licensePlate = inputLicensePlate;
this.paintColor = inputPaintColor;
this.areTailingWorking = inputAreTaillightsWorking;
}


}

And under 'Main' I want to start to create instances for my Class, as in the image attached. However, even though inside the brackets the values are proposed, I cannot assign them, and they are just not recognized:

I think this might have something to do with a configuration of IntelliJ IDEA, but not sure. I already tried changing some configurations, but it didn't work.

Thanks in advance!

0
1 comment

This constructor requires you to specify the actual values when creating the class.

Like this:

new Car(12.5, "ZZZAAA", ...) etc.

The issue has nothing to do with the IDE.

1

Please sign in to leave a comment.