Advertisement
sergAccount

Untitled

Aug 23rd, 2020
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 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.Student;
  9.  
  10. /**
  11.  *
  12.  * @author Admin
  13.  */
  14. public class Main {
  15.     //
  16.     public static void printStudent(Student s){
  17.         if(s!=null){
  18.             System.out.println("s.name=" + s.getName());
  19.             System.out.println("s.age="  + s.getAge());
  20.         }
  21.     }
  22.     // main + tab
  23.     public static void main(String[] args) {
  24.         // Ctrl+Shift+I - хот кей для добавления оператора импорта
  25.         Student s;
  26.         // что можно присвоить переменной s - ???
  27.         // 1) null - ссылка на пустоту
  28.         s = null;
  29.         System.out.println("s=" + s);
  30.         // 2) можем присвоить объект
  31. //        s = new Student();
  32. //        //
  33. //        Student s2 = new Student();
  34. //        // выводим имя студента - вызвыаем метод getName на объекте s2
  35. //        System.out.println("s2.name="   + s2.getName());
  36. //        System.out.println("s2.getAge=" + s2.getAge());
  37.  
  38.         s = new Student("Alex", 10);
  39.         Student s2 = new Student("Nick", 20);
  40.         // что мы можем сделать с объектом s2 ???
  41.         // вывести на экран студента (s2)
  42.         //System.out.println("s2=" + s2);        
  43.         System.out.println("s2=" + s2.getName() + "_" + s2.getAge());
  44.         //
  45.         Student s3 = null;
  46.         // вывести на экран имя и возраст студента s3        
  47. //        boolean res = (s == null);
  48. //        res = (s != null);        
  49.         if(s3!=null){
  50.             System.out.println("s3=" + s3.getName() + "_" + s3.getAge());
  51.         }                
  52.         printStudent(s3);
  53.         System.out.println("OK");        
  54.        
  55.         // сравнить двух студентов
  56.         //boolean result = s > s2;                
  57. //        int i = 10;
  58. //        System.out.println("i=" + i);
  59. //        boolean result = i > 1;
  60. //        System.out.println("result=" + result);
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement