aspose file tools*
The moose likes Beginning Java and the fly likes static int not incrementing, constructor not called. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static int not incrementing, constructor not called." Watch "static int not incrementing, constructor not called." New topic
Author

static int not incrementing, constructor not called.

Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
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
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

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

Joined: Oct 13, 2005
Posts: 40029
    
  28
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

Joined: Oct 13, 2005
Posts: 40029
    
  28
. . . and welcome to the Ranch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static int not incrementing, constructor not called.