Advertisement
sergAccount

Untitled

Aug 16th, 2020
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.spec;
  7.  
  8. import com.spec.model.Car;
  9.  
  10. public class Main {
  11.     //
  12.     public static void main(String[] args) {
  13.         // объявление переменной типа Car
  14.         //Ctrl+Shift+I
  15.         Car c1; // c1 - имя переменной, Car
  16.         // создание объекта типа Car
  17.         // для создания объекта используем ключевое слово new
  18.         c1 = new Car(); // new Car()
  19.         // объявляем переменную и присваиваем значение-объект данной переменной
  20.         Car c2 = new Car();
  21.        
  22.         // использование объекта - вызов метода - используем оператор точка
  23.         String color1 = c1.getColor();
  24.         System.out.println("color1=" + color1);        
  25.         //
  26.         c1.setColor("red");
  27.         System.out.println("color1=" + c1.getColor());        
  28.         System.out.println("c1.speed=" + c1.getSpeed());
  29.        
  30.         // создаем новый авто - используем конструктор класса с параметром
  31.         Car c3 = new Car("blue");
  32.         System.out.println("color.c3=" + c3.getColor());        
  33.         //
  34.         c3.speedUp(10);
  35.         System.out.println("c3.speed=" + c3.getSpeed());
  36.         c3.speedUp(20);        
  37.         System.out.println("c3.speed=" + c3.getSpeed());
  38.         c3.speedUp(40);
  39.         System.out.println("c3.speed=" + c3.getSpeed());        
  40.         c3.speedUp(-10);
  41.         System.out.println("c3.speed=" + c3.getSpeed());                
  42.     }    
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement