Create and Run Your First Java Application. Tasks
Car Class
- Create three classes:
Car
in thecom.company.vehicles
package,Engine
in thecom.company.details
package, andDriver
in thecom.company.professions
package. All three classes are in different packages. - In the
main()
method of theCar
class, create objects of theEngine
andDriver
classes. When theCar
program runs, it should print "I'm driving!" to the console. Compile and run the program. - Use command-line arguments when running
Car
: the program should accept multiple arguments and print them in the following format:Value: arg1 Value: arg2
Solution on Patreon.
Using the -cp Flag for Project Compilation
- Move the
com.company.professions
package to a separate project. - Add object creation for the
Engine
andDriver
classes in theCar
class:Engine engine = new Engine(); Driver driver = new Driver();
We haven't covered object creation yet; this will be explained in future lessons. Here, the focus is on referencing other classes. - Package the
com.company.professions
package into a JAR file and copy it to thelib
directory. - When compiling and running the
Car
class, specify the JAR file in the-cp
option.
Solution on Patreon.

Please log in or register to have a possibility to add comment.