[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

nested class vs inner class

Posted on 2016-08-16
5
Medium Priority
?
104 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

649 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