0% found this document useful (0 votes)
29 views2 pages

3 - Getter and Setter Example 1

Uploaded by

Juan Dela Cruz
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)
29 views2 pages

3 - Getter and Setter Example 1

Uploaded by

Juan Dela Cruz
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/ 2

public class Car4 {

String make;
String model;
int year;
int speed;

//Constructor
public Car4(String make,String model, int year, int speed){
this.make=make;
this.model=model;
this.year=year;
this.speed=speed;
}

//Getter for properties


public String getMake(){
return make;
}

public String getModel(){


return model;
}

public int getYear(){


return year;
}

public int getSpeed(){


return speed;
}

//Setter for properties


public void setMake(String make){
this.make = make;
}

public void setModel(String model){


this.model=model;
}

public void setYear(int year){


this.year=year;
}

public void setSpeed(int speed){


this.speed=speed;
}
public static void main(String[] args) {
//Create object
Car4 myCar = new Car4("","",0,0);

//set and print the value of properties


myCar.setMake("Honda");
myCar.setModel("Civic");
myCar.setYear(2021);
myCar.setSpeed(180);

//get the value of properties amd print


System.out.println("Make "+ myCar.getMake());
System.out.println("Model "+ myCar.getModel());
System.out.println("Year "+ myCar.getYear());
System.out.println("Speed "+ myCar.getSpeed());

}
}

You might also like