+1 vote
in JAVA by
Explain difference between nested static class and top level class?

1 Answer

0 votes
by

One of the fundamental questions from Java basics. I ask this question only to junior Java developers of 1 to 2 years of experience as it's too easy for an experience Java programmers. The answer is simple, a public top level class must have the same name as the name of the source file, there is no such requirement for nested static class. A nested class is always inside a top level class and you need to use the name of the top-level class to refer nested static class e.g. HashMap.Entry is a nested static class, where HashMap is a top level class and Entry is nested static class.

Related questions

0 votes
asked May 5, 2021 in JAVA by SakshiSharma
0 votes
asked Oct 17, 2020 in JAVA by rahuljain1
...