Solved

nested class vs inner class

Posted on 2016-08-16
5
63 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
  • 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 26

Accepted Solution

by:
dpearson earned 250 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 250 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
what is a "java.lang.System Property"   ? 20 65
egit plugin on eclipse 8 62
servlet example 17 28
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now