Java Static nested class

0 votes

I was going through some examples and found this code with static nested class:

public class LinkedList<E> ... {
...

 private static class Entry<E> { ... }

}

But I am not able to understand, why one should go for a static nested class instead of a general inner class? Please explain.

Jun 7, 2018 in Java by 93.lynn
• 1,550 points
32 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hi, to understand their usage, you must know the difference between the two.

As you might know that a nested class is by default a member of its enclosing class. An inner class (or the non-static nested class) can access any of the data members of its enclosing class i.e., even if its declared private, it will be accessible by it. Whereas a static nested class can’t do so, rather it can interact with the instances of its outer class. In other words, a static nested class behaves just like a top-level class. In your example, since your LinkedList. Entry class in not accessing any of the LinkedList members, it is kept as static.

Hope this clears your doubt.

answered Jun 7, 2018 by v.liyyah
• 1,290 points

Related Questions In Java

0 votes
1 answer

Why are you not able to declare a class as static in Java?

Declare your class like this: public class eOAuth ...READ MORE

answered Oct 4, 2018 in Java by Daisy
• 8,020 points
33 views
0 votes
1 answer

How to use nested class in Java?

This program will help you understand the ...READ MORE

answered Mar 3 in Java by Priyaj
• 56,120 points
13 views
0 votes
2 answers

When to use Static Methods in Java?

A static method has two main purposes: For ...READ MORE

answered Aug 9, 2018 in Java by samarth295
• 2,190 points
58 views
0 votes
1 answer

Can Static methods be inherited in java?

A subclass inherits all of the public ...READ MORE

answered Apr 30, 2018 in Java by Daisy
• 8,020 points
33 views
+1 vote
2 answers

What are inner classes and static nested classes?

Nested classes are divided into two categories: ...READ MORE

answered Dec 3, 2018 in Java by Sushmita
• 6,820 points
27 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,360 points

edited Nov 6, 2018 by Omkar 4,641 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
1,237 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
3,532 views
0 votes
1 answer

Static methods can't be abstract in Java

Well, Java doesn't allow this because of ...READ MORE

answered Oct 12, 2018 in Java by v.liyyah
• 1,290 points
36 views
0 votes
1 answer

NoClassDefFoundError in Java

Can’t tell you the exact reason as ...READ MORE

answered May 25, 2018 in Java by v.liyyah
• 1,290 points
62 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.