Answers for "setter&getter java"

-1

setter&getter java

public static void main(String[] args) {
  Vehicle v1 = new Vehicle();
  v1.setColor("Red");
  System.out.println(v1.getColor());
}

// Outputs "Red"
Posted by: Guest on May-16-2021
-2

setter&getter java

public class Vehicle {
  private String color;
  
  // Getter
  public String getColor() {
    return color;
  }
  
  // Setter
  public void setColor(String c) {
    this.color = c;
  }
}
Posted by: Guest on May-16-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language