0

While reading Java I came across one question:

Can a static class contains instance initialization block?

1
  • Static classes are not inner-classes, by definition. Commented Nov 25, 2017 at 11:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.