Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ObjectsAndClasses;
- public class Phone {
- //характеристики (цвят, модел, цена) -> полета
- private String color;
- private String model;
- private double price;
- //поведение -> методи
- //1. конструктор -> метод, за създаване на обект от класа
- public Phone(String color, String model, double price) {
- //нов обект -> color = null, model = null, price = 0
- this.color = color;
- this.model = model;
- this.price = price;
- }
- //2. getters and setters
- //getter -> достъп до полето
- //setter -> задавам стойност на полето
- //поле model -> get and set
- public String getModel() {
- return this.model;
- }
- public void setModel(String model) {
- this.model = model;
- }
- //поле color -> get and set
- public String getColor() {
- return this.color;
- }
- public void setColor(String color) {
- this.color = color;
- }
- //поле price -> get and set
- public double getPrice() {
- return this.price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- public void ring () {
- System.out.println("Ring Ring");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment