what is inner class?

Answer Posted / midhun h kumar

Inner classes-> Nested top-level classes, Member classes,
Local classes, Anonymous classes

Nested top-level classes- If you declare a class within a
class and specify the static modifier, the compiler treats
the class just like any other top-level class.
Any class outside the declaring class accesses the nested
class with the declaring class name acting similarly to a
package. eg, outer.inner. Top-level inner classes implicitly
have access only to static variables.There can also be inner
interfaces. All of these are of the nested top-level variety.

Member classes - Member inner classes are just like other
member methods and member variables and access to the member
class is restricted, just like methods and variables. This
means a public member class acts similarly to a nested
top-level class. The primary difference between member
classes and nested top-level classes is that member classes
have access to the specific instance of the enclosing class.

Local classes - Local classes are like local variables,
specific to a block of code. Their visibility is only within
the block of their declaration. In order for the class to be
useful beyond the declaration block, it would need to
implement a
more publicly available interface.Because local classes are
not members, the modifiers public, protected, private, and
static are not usable.

Anonymous classes - Anonymous inner classes extend local
inner classes one level further. As anonymous classes have
no name, you cannot provide a constructor.

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many types of design patterns are there?

529


What is length in java?

568


Does unicode support all languages?

518


Explain java coding standards for variables ?

665


Explain wait(), notify() and notifyall() methods of object class ?

591






What are the 5 types of research methods?

585


What does file separator do in java?

534


What is main string [] args?

520


What are the benefits of java?

571


Compare overloading and overriding?

557


What are the classes of java?

537


What is core java used for?

507


What is the purpose of the file class in java programming?

526


Can static methods access instance variables in java?

571


What is the syntax and characteristics of a lambda expression? Explain

537