Advertisement
sergAccount

Untitled

Dec 13th, 2020
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 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.mycompany.ja9;
  7.  
  8. /**
  9.  *
  10.  * @author Admin
  11.  */
  12. public class Main {
  13.    
  14.     public static void main(String[] args) {
  15.         // new - ключевое слово для создания объектов
  16.         // объявлем переменную типа Car
  17.         Car c1;
  18.         // создание объекта
  19.         c1 = new Car();
  20.         //
  21.         Car c2 = new Car();
  22.         Car c3 = null;        
  23.         Car c4 = c1;
  24.         //new Car();
  25.         // вызов метода для объекта типа Car
  26.         c1.getColor(); // вызов метода getColor для объекта типа Car
  27.         // имя_переменной.имя_метода(); - общий синтаксис для вызова метода
  28.         String c1Color = c1.getColor();
  29.         System.out.println("c1Color=" + c1Color);
  30.         //
  31.         c1.setColor("red");
  32.         System.out.println("c1.getColor()=" + c1.getColor());
  33.         System.out.println("c1.getSpeed()=" + c1.getSpeed());
  34.        
  35.         if(c3!=null){
  36.             c3.getColor();
  37.         }
  38.         // доступ к свойствам
  39.         //System.out.println("с3.m=" + c1.m);
  40.         //c1.m = 1000;
  41.     }    
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement