Create and Run Your First Java Application. Tasks
Car Class
- Create three classes:
Carin thecom.company.vehiclespackage,Enginein thecom.company.detailspackage, andDriverin thecom.company.professionspackage. All three classes are in different packages. - In the
main()method of theCarclass, create objects of theEngineandDriverclasses. When theCarprogram 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.professionspackage to a separate project. - Add object creation for the
EngineandDriverclasses in theCarclass: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.professionspackage into a JAR file and copy it to thelibdirectory. - When compiling and running the
Carclass, specify the JAR file in the-cpoption.
Solution on Patreon.
Курс 'Java для начинающих' на Udemy
Please log in or register to have a possibility to add comment.