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 2, 2020 3:25 PM
Views: 6
  1. class Planet {
  2.     public String name;
  3.     public int moons;
  4.  
  5.     public Planet(String name, int moons) {
  6.         this.name = name;
  7.         this.moons = moons;
  8.     }
  9. //      public String toString(){  //toString methodu override yaparsak planet i yazdirabiliriz
  10. //              return name+moons;
  11. //      }
  12. }
  13.  
  14. public class Question135 {
  15.  
  16.  
  17.     public static void main(String[] args) {
  18.         Planet[] planets = {
  19.                 new Planet("Mercury", 0),
  20.                 new Planet("Venus", 0),
  21.                 new Planet("Earth", 1),
  22.                 new Planet("Mars", 2),
  23.  
  24.         };
  25.  
  26.         System.out.println(planets);
  27.         System.out.println(planets[2].name);
  28.         System.out.println(planets[2].moons);
  29.  
  30.     }