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,570 points
50 views

1 answer to this question.

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,300 points

Related Questions In Java

0 votes
2 answers
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,900 points
26 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
112 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,050 points
63 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,880 points
120 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,380 points

edited Nov 6, 2018 by Omkar 10,046 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,110 points
2,261 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,110 points
5,885 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,300 points
61 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,300 points
558 views