Войти
  • 46804Просмотров
  • 1 год назадОпубликованоBro Code

Learn Java getters and setters in 10 minutes! 🔐

#java #javatutorial #javacourse public class Main { public static void main(String[] args) { // They help protect object data and add rules for accessing or modifying them. // GETTERS = Methods that make a field READABLE. // SETTERS = Methods that make a field WRITEABLE. Car car = new Car("Charger", "Yellow", 10000); ("Blue"); (5000); ( () + " " + () + " " + ()); } } public class Car { private String model; private String color; private int price; Car(String model, String color, int price){ = model; = color; = price; } String getModel(){ return ; } String getColor(){ return ; } String getPrice(){ return "$" + ; } void setColor(String color){ = color; } void setPrice(int price){ = price; } }