desislava_topuzakova

Demo class: Phone

Mar 13th, 2022
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package ObjectsAndClasses;
  2.  
  3. public class Phone {
  4.     //характеристики (цвят, модел, цена) -> полета
  5.     private String color;
  6.     private String model;
  7.     private double price;
  8.  
  9.     //поведение -> методи
  10.     //1. конструктор -> метод, за създаване на обект от класа
  11.     public Phone(String color, String model, double price) {
  12.         //нов обект -> color = null, model = null, price = 0
  13.         this.color = color;
  14.         this.model = model;
  15.         this.price = price;
  16.     }
  17.  
  18.     //2. getters and setters
  19.     //getter -> достъп до полето
  20.     //setter -> задавам стойност на полето
  21.  
  22.     //поле model -> get and set
  23.     public String getModel() {
  24.         return this.model;
  25.     }
  26.  
  27.     public void setModel(String model) {
  28.         this.model = model;
  29.     }
  30.  
  31.     //поле color -> get and set
  32.     public String getColor() {
  33.         return this.color;
  34.     }
  35.  
  36.     public void setColor(String color) {
  37.         this.color = color;
  38.     }
  39.  
  40.     //поле price -> get and set
  41.     public double getPrice() {
  42.         return this.price;
  43.     }
  44.  
  45.     public void setPrice(double price) {
  46.         this.price = price;
  47.     }
  48.  
  49.     public void ring () {
  50.         System.out.println("Ring Ring");
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment