0% found this document useful (0 votes)
13 views3 pages

Java Car Class Implementation

The document defines a Car class with private fields for make, model, and year and public getters and setters to access and modify these fields. It also includes a toString method to output the car details. The main method creates some Car objects, modifies their properties, and outputs the results.

Uploaded by

Pirzada Swati
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Java Car Class Implementation

The document defines a Car class with private fields for make, model, and year and public getters and setters to access and modify these fields. It also includes a toString method to output the car details. The main method creates some Car objects, modifies their properties, and outputs the results.

Uploaded by

Pirzada Swati
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//By PirZada…..

class Car
{
private String make;
private String model;
private int year
public Car(String make,String model,int year)
{
[Link] = make;
[Link]= model;
[Link] = year;
}
public String setCarMake(String make)
{
[Link] = make;
return make;
}
public String getCarMake()
{
return make;
}
public String setCarModel(String model)
{
[Link] = model;
return model;
}
public String getCarModel()
{
return model;
}
public int setCarYear(int year)
{
[Link] = year;
return year;
}
public int getCarYear()
{
return year;
}
public String toString()
{
return "Car make: " + make + "
Car model: " + model + " Car Year:" + year;
}
public static void main (String[] args)
{
Car car1 = new Car("Toyota", "Corolla" , 1997);
Car car2 = new Car("Nissan", "Murano" , 2005);
Car car3 = new Car("Infinity", "Mazda" , 2014);
[Link]("BMW");
[Link](car1);
[Link]([Link]());
[Link]("Altima");
[Link](car2);
[Link]([Link]());
[Link](2012);
[Link](car3);
[Link]([Link]());
}
}

You might also like