with Complete Solutions
Consider the following code segment:
```java
public class Car {
private String model;
private int year;
public Car(String model, int year) {
this.model = model;
this.year = year;
}
public String getModel() {
return model;
}
public int getYear() {
1
, return year;
}
}
```
What is the purpose of the `getModel()` and `getYear()` methods in this class?
✔✔ The `getModel()` and `getYear()` methods are accessor methods (getters) that return the
values of the `model` and `year` instance variables, respectively. They allow controlled access to
the private fields from outside the class.
Consider the following code segment:
```java
public class Rectangle {
private int length;
private int width;
public Rectangle(int length, int width) {
this.length = length;
this.width = width;
2