answersLogoWhite

0

When do you use inner classes?

Updated: 12/11/2022
User Avatar

Wiki User

14y ago

Best Answer

You use inner classes when you know you'll never need to access that class from anywhere else.

A common use of this is in a linked list implementation:

public class LinkedList {

private class LinkedListNode {

}

}

There's no reason for any other class to have access to your node class, so it should be an inner class.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When do you use inner classes?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Compare anonymous class with abstract class?

Abstract Classes contain the work abstract in it. It is used when you know that you will need to use an object of its type but do not know the inner workings yet. Anonymous classes are those classes that are constructed on the fly. You need to know its inner workings.


How many types of classes are found in java?

1.Outer Classes 2. Inner Classes


How many classes should be included in each java file?

You can only have one non-inner public classes per java file and that class name must match the filename. The java file can also have any number of inner classes and anonymous classes.


Which classes use daggers in Dragon Fable?

Rogues are the class that use daggers, but all the classes can use them.


Why you use inner loop and outer loop?

Sometimes you have to use nested loops, in this case one of them is the outer, the other is the inner.


What two classes of vertebrate use external fertilisation?

what two classes of vertebrates use external fertilisation


What are inner classes?

Quite simply, an inner class is one class within another. Typically the inner class will be a private inner class, and will only be used by the outer class. class MyOuterClass { class MyInnerClass { } }


How can you use 'inner core' in a sentence?

The inner core is made up of an iron-nickel fluid.


How do you use inner planets in a sentence?

I hesitate to admit that I was raised on one of the inner planets. The inner planets are not gaseous, like the outer planets.


Can you use inner core in a sentence?

The inner core is made up of an iron-nickel fluid.


What is the collective noun for classes?

The standard use of the collective noun 'classes' is 'classes of students'. The noun 'class' (or the plural form 'classes') is a general collective noun for people or things, for example 'classes of travelers' or 'classes of work animals'.


Inner classes in java?

An inner class is a class within a class: class MyClass { class MyInnerClass { } } Inner classes in Java are normally used for things like the nodes of a linked list.