0

I am trying to learn java. I need to write a program about car rental. I want to access variable whose value is given with constructor. I have written a code like below. It gives error on each line at main.

public class CarRental {
   public int id;
   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
       Customer varCust = new Customer(1,"Joona","Lappeenranta");
       Car varCar = new Car(1,"Mercedes",2013);
       write(id);
   }

   public class Customer {
       public Customer(int idCust, String Name, String Contact) {
           id=idCust;
       }

   public class Car {
       public Car (int idCar, String Model, int myear) {

       }
   }

   public void writethat(int what) {
       System.out.print(what);

   }
}
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
quanta
  • 1
  • "It gives error". What error? – resueman Jan 15 '16 at 15:10
  • You called write(id) , but I don't see any method named write() in your code. There is one writeThat method – Pritam Banerjee Jan 15 '16 at 15:14
  • thx for the answers i changed the write(id) as writethat(id) and the error was Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static variable this cannot be referenced from a static context at carrental.CarRental.main(CarRental.java:19) – quanta Jan 15 '16 at 15:25

0 Answers0