Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn Java getters and setters in 10 minutes! 🔐
Play lesson

Java tutorial for beginners ☕ - Learn Java getters and setters in 10 minutes! 🔐

5.0 (4)
40 learners

What you'll learn

This course includes

  • 12 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#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); car.setColor("Blue"); car.setPrice(5000); System.out.println(car.getColor() + " " + car.getModel() + " " + car.getPrice()); } } public class Car { private String model; private String color; private int price; Car(String model, String color, int price){ this.model = model; this.color = color; this.price = price; } String getModel(){ return this.model; } String getColor(){ return this.color; } String getPrice(){ return "$" + this.price; } void setColor(String color){ this.color = color; } void setPrice(int price){ this.price = price; } }

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere