?
Solved

nested class vs inner class

Posted on 2016-08-16
5
Medium Priority
?
98 Views
Last Modified: 2016-08-20
Hi,

What are differenced between nested class vs inner class. when and how and where we use each one. please advise
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:CPColin
ID: 41758794
There's no difference; the two terms mean the same thing.
0
 
LVL 28

Accepted Solution

by:
dpearson earned 1000 total points
ID: 41758828
To me "nested class" can mean either "static class" or "inner class".

So like this:
public class Outer {
   public static class StaticNested { }    // Note: "static" keyword here.  This is a static nested class.
}

public class Outer {
   public class Inner { }     // Can also be considered a non-static nested class
}

Open in new window


You asked a similar question a little while ago gudii9 about when to use these two and my advice was "always use the static version" - because they behave like normal classes.

Inner classes have special and confusing behaviors.  In my opinion they're a mistake in the Java language design and best avoided.

Doug
0
 
LVL 7

Author Comment

by:gudii9
ID: 41759476
To me "nested class" can mean either "static class" or "inner class".

so inner class means non static one right which is one kind of nested class right ? ( while static lass is other kind right?)
0
 
LVL 14

Assisted Solution

by:CPColin
CPColin earned 1000 total points
ID: 41759499
Looks like Doug is right. Per the language specification:
An inner class is a nested class that is not explicitly or implicitly declared static.
If you do GUI work, you'll become pretty familiar with inner (non-static) classes. If you use lambda expressions, you're secretly using inner classes, too. The key with them being non-static is that they can access stuff in the outer class, while static nested classes cannot.
0
 
LVL 7

Author Comment

by:gudii9
ID: 41763713
To me "nested class" can mean either "static class" or "inner class".

So like this:
public class Outer {
   public static class StaticNested { }    // Note: "static" keyword here.  This is a static nested class.
}

public class Outer {
   public class Inner { }     // Can also be considered a non-static nested class
}


above is clear
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question