answersLogoWhite

0

Benefit of inner class in java?

Updated: 12/7/2022
User Avatar

Wiki User

14y ago

Best Answer

Inner classes are very useful for classes that are written specifically to be used with the encompassing class. A good example of this would be a LinkedListNode class being part of a LinkedList class:

public class LinkedList {

private LinkedListNode root;

private class LinkedListNode {

private Object data;

private LinkedListNode nextNode;

}

} No class except your LinkedList class needs to know anything about the LinkedListNode class. So we hide it so no one else needs to worry about what it does.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Benefit of inner class in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is inline declaration?

It is a declaration of java class in method body which called "inner class"


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.


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.


Extension file for Java?

Java source files have the .java extension, compiled Java class files have the .class extension.


Does interface contains classes or not?

While not very common an interface in Java can contain a class. Most interface definitions strictly provide an interface and don't include inner classes.An example is the java.text.AttributedCharacterIteratorinterface found in the J2SE API which includes a public static inner class Attribute. The inner class is accessed externally as AttributedCharacterIterator.Attribute.


What happens when you declare class as a static in Java?

Declaring an inner class static means that class only has access to the "outer" class public and private static fields. A non-static inner class has access to the outer class's instance data. Top-level classes cannot be declared static. The advantage of a static inner class is that it doesn't need an instance of the containing class to work and it's bytecode class size is smaller for that reason - less overhead.


The actions in a java class are called?

The actions in a java class are called methods.


Why you start java program by class?

without class non of the folder can run so the java program should start in class we can use the class without object in java


When java uses compiler?

What i know is java we will use compiler when it want to get class file(file with .class extension) from java file(file with .java extension).


How do you call main class with in main class in java?

We can't call a class. We always call a method in java.


What class begins java class hierarchy?

Class


Can you declared constructor as private?

If you declare the main method anything other than public, it will not run. If you declare main method as private, you would not be able to execute the class as a standalone java program. Any java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone java file and would not allow you to run it.