• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static int not incrementing, constructor not called.

 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.

I'm playing around with static variables and constructors on a small program to try things out. Why won't number_cars increment and the constructors run?

CarTestDrive.java

taxi.java
 
Paul Clapham
Sheriff
Posts: 21000
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have any constructors in your vehicle class. That code from lines 46 to 48 in your post is a method named vehicle(), not a constructor. Remove the return type ("void") if you want to change it into a constructor.

One more thing: although your code is syntactically correct, it would help very much if you followed the code conventions which are generally used across the Java world. Following these standards, class names are capitalized: Vehicle, Car, and so on. Variable and method names start with lower-case letters and are "camel-cased" if they consist of more than one word: numberOfCars, driveHand, and so on. Almost everybody uses these conventions, to the extent that code which doesn't follow them (like the code you posted) is hard to read.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you appear to have two number_cars fields. If you find our FAQ, or Google for hiding fields, you find out that proactice can be very confusing.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic