fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Car car1 = new Car(2);
  13. System.out.println("car1 = "+car1.getCarDoors());
  14.  
  15. Car car2 = new Car(4);
  16. System.out.println("car2 = "+car2.getCarDoors());
  17.  
  18. for(int = 0;i<10;i++){
  19. car2.movieForward();
  20. System.out.println("car2 speed = "+car2.getCarDoors());
  21. }
  22. }
  23. }
  24.  
  25. class Car{
  26. private int carDoors;
  27. private int speed =10;
  28.  
  29. public Car(int doors){
  30. this.carDoors = doors;
  31. }
  32.  
  33. public int getCarDoors(){
  34. return carDoors;
  35. }
  36.  
  37. public void movieForward(){
  38. speed++;
  39. }
  40. public int getSpeed(){
  41. return speed;
  42. }
  43.  
  44.  
  45. }
Success #stdin #stdout 0.09s 27656KB
stdin
Standard input is empty
stdout
car1 = 2
car2 = 4