Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: ulkir
Added: Jul 13, 2020 12:21 AM
Modified: Jul 13, 2020 12:27 AM
Views: 103
  1. //3 farkli sekilde import kullarnilabilir
  2.  
  3. package clothing.pants;
  4.  
  5. //line n1
  6.  
  7. import static clothing.Shirt.getColor;
  8.  
  9.  
  10. public class Jeans {
  11.  
  12.     public void matchShirt() {
  13.         //line n2
  14. //        String color= Shirt.getColor();
  15.  
  16.                 String color = getColor();
  17.  
  18.  
  19.  
  20.         if (color.equals("Green")) {
  21.             System.out.println("FIT");
  22.         }
  23.     }
  24.  
  25.     public static void main(String[] args) {
  26.         Jeans trouser = new Jeans();
  27.         trouser.matchShirt();
  28.  
  29.     }
  30. }
  31.  
  32.  
  33. package clothing;
  34.  
  35. public class Shirt {
  36.  
  37.     public static String getColor() {  //buradaki getColor(), Shirt classin in bir metodudur ve cagirmak icin once
  38.         // import yapilir
  39.         //import clothing.Shirt
  40.         //String color = Shirt.getColor(); bu sekilde metod cagrilmmis olur
  41.         return "Green";
  42.     }
  43. }
  44.  
  45. //1. yontem
  46. //line 1 e gelebilecek ifadeler ve line 2 olabilecegi ifadeler
  47. //import clothing.Shirt;  //eger line 1 boyle olursa
  48. //String color = Shirt.getColor();  //line 2 bu ifade olur
  49.  
  50. //2. yontem
  51. //import static clothing.Shirt.getColor;  //line n1
  52. //String color = getColor(); //line n2
  53.  
  54. //3. yontem
  55. //import clothing.*;  //line n1
  56. //String color = Shirt.getColor();  //line n2
  57.  
  58. //4. yontem
  59. //import static clothing.Shirt.*; //line n1
  60. //String color = getColor(); //line n2
  61.  
  62. //* oldugunda ne kadar clothing.* class varsa hepsine ulasilabilir
  63. //clothing.Shirt.*;  clothing paketinde yer alan Shirt sinifindaki tum metodlari alir
  64.  
  65. //import un kurali ne kadar paket varsa hepsi olmali
  66.  
  67.