Expression Statements

Certain kinds of expression are counted as statements. You write any expression, put a semicolon after it, and voila, it's an expression statement. In particular, an assignment, method invocation, the creation of a object by calling a constructor (looks like a method call, and the keyword “new” is used so we can tell them apart), and pre-increment, post-increment, and decrement are all expressions that can be statements.

a = b;                // assignment
w.setSize(200,100);   // method invocation
new WarningWindow(f); // instance creation
++i;                  // pre-increment

An expression statement is executed by evaluating the expression.

If the expression is an instance creation, you usually save a reference to it so that you can access fields and invoke methods on that object. For example, you have:

foo = new WarningWindow(f); // instance creation

not:

new WarningWindow(f); // instance, but no ref saved

However, there are certain classes we'll see later that you can instantiate for which you don't necessarily need to save a reference. The two main examples are Threads and inner (nested) classes. They are fine doing their work without further input from you. So, while you usually keep a reference to a newly instantiated class, you might occasionally see no reference kept.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.51.153