Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
{) and close brace (}) characters.
static keyword.
if statement block.
static keyword in a top-level class or another nested top-level class.
These tips and cautions will help you write better programs and save you from agonizing over why the compiler produces error messages.
private, protected, or public keywords to determine that class's level of accessibility to code outside the enclosing class.
There is some confusion regarding nested classes and static members. That confusion results from compiler error messages that
appear when the compiler discovers static field, method, or class declarations within inner classes. It turns out that only
nested top-level classes can declare such members. To the best of my knowledge, the reason has something to do with keeping
Java more object-oriented. To see these errors for yourself, compile the following InnerStatic source code:
// InnerStatic.java
class InnerStatic
{
// A is a nested top-level class.
static class A
{
// static field, method, and class declarations are permitted in a
// nested top-level class.
static int x = 1;
static void methodA ()
{
}
static class FooA
{
}
}
// B is an instance inner class.
class B extends A
{
// static field, method, and class declarations are not permitted
// in an instance inner class.
static int y = 2; // Compiler error.
static void methodB () // Compiler error.
{
System.out.println (x); // This statement is okay.
}
static class FooB // Compiler error.
{
}
// final static field declarations are permitted in an instance
// inner class.
final static int Z = 3;
}
}
InnerStatic declares nested top-level class A and instance inner class B. Each class contains three static member declarations: A declares x, static void methodA(), and FooA; whereas B declares y, static void methodB(), and FooB. Although A's declarations are legal, B's declarations are not. However, a close look at B's source code reveals two legal uses of static fields: