Читать книгу OCP Oracle Certified Professional Java SE 17 Developer Study Guide - Jeanne Boyarsky - Страница 34
Sample Test Class
ОглавлениеThroughout this book, we present numerous code snippets and ask you whether they'll compile or not and what their output is. You can place these snippets inside a simple Java application that starts, executes the code, and terminates. You can accomplish this by compiling and running a public
class containing a main()
method and adding the necessary import
statements, such as the following:
// Add any necessary import statements here public class TestClass { public static void main(String[] args) { // Add test code here // Add any print statements here System.out.println("Hello World!"); } }
This application isn't particularly interesting—it just outputs Hello World!
and exits. That said, you could insert many of the code snippets presented in this book in the main()
method to determine whether the code compiles, as well as what the code outputs when it does compile.