0% found this document useful (0 votes)
21 views

OOP Concept Java

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)
21 views

OOP Concept Java

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
You are on page 1/ 3

//By PirZada…..

class Car
{
private String make;
private String model;
private int year
public Car(String make,String model,int year)
{
this.make = make;
this.model= model;
this.year = year;
}
public String setCarMake(String make)
{
this.make = make;
return make;
}
public String getCarMake()
{
return make;
}
public String setCarModel(String model)
{
this.model = model;
return model;
}
public String getCarModel()
{
return model;
}
public int setCarYear(int year)
{
this.year = 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);
car1.setCarMake("BMW");
System.out.println(car1);
System.out.println(car1.getCarYear());
car2.setCarModel("Altima");
System.out.println(car2);
System.out.println(car2.getCarMake());
car3.setCarYear(2012);
System.out.println(car3);
System.out.println(car3.getCarModel());
}
}

You might also like