I made a java program which prints color of car and i called for the object and it didn't gave me the right result. Pls help

public class car {
	//instances variable
	static String carColor;
	static String carModel;
	static int carDime;
	public car(String color,String model,int dime ) {
		carModel = model;
	public static void main (String[] args) {
		car Jaguar = new car("Red","AAB",3);
		car Ferrari = new car("Blue","BBA",4);

It gives the result “Blue” but it have to give “Red” according to me ! pls correct me!

you used the static keyword, The static keyword belongs to the class than an instance of the class. So now all your cars share a single color, carModel and carDime.

1 Like