0

While reading Java I came across one question:

Can a static class contains instance initialization block?

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142

1 Answers1

1

Static (or nested) classes can have both instance and static initialization blocks.

Consider a nested class as

a top-level class that has been nested in another top-level class for packaging convenience.
The Java Tutorials > Nested Classes

On the other hand, inner classes can't have a static initialization block. No static content is allowed within them.

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142