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 8, 2018 in Java by 93.lynn
• 1,600 points
526 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 8, 2018 by v.liyyah
• 1,300 points

Related Questions In Java

0 votes
0 answers

Java inner class and static nested class

What is the main difference between an ...READ MORE

Apr 21, 2022 in Java by Rahul
• 3,380 points
226 views
0 votes
2 answers

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

A static keyword  can be used with ...READ MORE

answered Jun 11, 2019 in Java by Neha
• 330 points
1,132 views
0 votes
1 answer

How to use nested class in Java?

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

answered Mar 3, 2019 in Java by Priyaj
• 58,090 points
355 views
0 votes
2 answers

When to use Static Methods in Java?

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

answered Aug 10, 2018 in Java by samarth295
• 2,220 points
15,563 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,910 points
3,637 views
0 votes
1 answer

Static Classes In Java

Java has static nested classes but it sounds like ...READ MORE

answered Dec 23, 2020 in Java by Gitika
• 65,910 points

edited Jul 5, 2023 by Khan Sarfaraz 717 views
+5 votes
4 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,450 points

edited Nov 7, 2018 by Omkar 79,558 views
+1 vote
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,500 points
7,965 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
866 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
2,294 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP