File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static int not incrementing, constructor not called.

 
Rob Brew
Ranch Hand
Posts: 101
  • 0
  • 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
Pie
Posts: 20187
26
MySQL Database
  • 0
  • 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
Pie
Posts: 47274
52
  • 0
  • 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
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic