answersLogoWhite

0

What are inner classes?

Updated: 8/11/2023
User Avatar

Wiki User

16y ago

Best Answer

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 {

}

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

16y ago

Next time you ask a question give more detail because I DO NOT know what the heck your talking about!

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are inner classes?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


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.


When do you use inner classes?

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.


Benefit of inner class in java?

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.


If you have two public classes in a java file what will be the error and how will you remove it?

Hmm, let me see, it is technically perfectly legal to have 2 classes in a single file, as long as one class is an inner class of the other: i.e. public class Stevo{ public class Fun{}}. But if you want two separate classes independent of each other the compiler would scream at you about class is public and should be declare in a file named [className].java. To fix this simply follow the compiler's instructions (shocking! the compiler actually was clear about something) and create a new file with the given name. But sometimes an inner class would be helpful, i.e. an iterator for the Abstract Data Type you are implementing.

Related questions

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.


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.


When do you use inner classes?

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.


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.


Which yoga studios in Calgary also offer pilates classes?

There are a number of yoga studios in Calgary that also offer Pilates classes. Some of those studios include 'Inner Space Yoga', 'Be Love Yoga Studio' and 'Heavens Fitness'.


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.


How many classes were there on passenger liners from the United Kingdom ca. 1900?

There were three classes of traveller. First class passengers had the best cabins with sea views. Second-class passengers were housed in the inner cabins. The Third-class passengers were given the smallest cabins in the 'bowels' of the ship.


Is it inner city or inner-city?

Inner City


Benefit of inner class in java?

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.


What is the inner-most part of the earth?

The inner core


The most inner layer of earth?

The inner core.