No-Argument Constructor Not Found in SuperclassYou get a compiler error stating that the superclass for a class you are compiling does not have a no-argument constructor. Every class constructor (other than the constructor for java.lang.Object ) calls one of the constructors for its immediate superclass. This call is an implicit call to the no-argument constructor for the superclass unless you explicitly call another constructor using the super keyword with the required parameter list. If the no-argument superclass constructor is being called, the compiler reports an error if this constructor does not exist or is declared private. Every class has a no-argument constructor by default unless it declares one or more constructors (that accept parameters) without explicitly declaring the no-argument version. If the no-argument constructor for the class you are extending was lost inadvertently, define it explicitly to correct this compiler error. Otherwise, you must include an explicit call to a valid superclass constructor as the first line of each subclass constructor using the super keyword. Inconsistent Class StateYou encounter a situation in which the state of an object, as defined by its fields, is inconsistent. A strength of OOP is the support it provides for encapsulation. If you have fields in a class that are interdependent, you should encapsulate them by declaring them as private. You can then control access to them using public get and set methods . Each set method should update any fields dependent on the field it modifies to maintain a consistent object state. Compiler Unable to Locate Source FilesYou are unable to compile classes that are assigned to packages. When you assign a class to a package, you must store the source file in a subdirectory structure that parallels the package hierarchy. For example, a public class named Car declared to be in package com.transportation.vehicle must be stored as Car.java in a com/transportation/vehicle subdirectory underneath the root directory from which javac is run. Note that you must compile from a directory one level above the root package directory when compiling classes assigned to packages. |