what is inner class?

Answers were Sorted based on User's Feedback



what is inner class?..

Answer / ranganathkini

An inner class is a class that is defined within the
definition of another class but outside any member
definition. Inner classes shud not be marked static.

An Inner class cannot be instantiated directly, i.e. one can
only instantiate an inner class by first instantiating the
outer class.

The Inner class has access to all the static as well as
non-static public/protected/private fields of its enclosing
outer class.

Inner classes are used to provide implementation that are
intimately connected with the enclosing outer class.

Is This Answer Correct ?    39 Yes 7 No

what is inner class?..

Answer / varsha vilas kalebag

inner classes has right to excess members of outer classes

Is This Answer Correct ?    11 Yes 1 No

what is inner class?..

Answer / amit kumar

A class within another class is known as nested class. There
are two type of nested class static nested class and non
static nested class.The static nested class did'nt access
its enclosed member function directly, where an non static
nested class can directly access. the non static nested
class is known as inner class. There are 4 type of nestated
class they are Nested top-level classes, Member classes,
Local classes, Anonymous classes....

Is This Answer Correct ?    7 Yes 1 No

what is inner class?..

Answer / 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

what is inner class?..

Answer / harish

Inner classes nest within other classes. A normal class is
a direct member of a package, a top-level class. Inner
classes, which became available with Java 1.1, come in four
flavors:
? Static member classes
? Member classes
? Local classes
? Anonymous classes
Let's take a quick look at each in turn.
Briefly, a static member class is a static member of a
class. Like any other static method, a static member class
has access to all static methods of the parent, or top-
level, class.
Like a static member class, a member class is also defined
as a member of a class. Unlike the static variety, the
member class is instance specific and has access to any and
all methods and members, even the parent's this reference.
Local classes are declared within a block of code and are
visible only within that block, just as any other method
variable.
Finally, an anonymous class is a local class that has no
name.

Is This Answer Correct ?    6 Yes 6 No

what is inner class?..

Answer / shahid

there is one "locha" in paragraph one of answer number 1.

since local classes are also inner classes which are defined within any block and that block can be a method's body.

class OuterSpace {
private String MessageComming = "is any body there";

void receiveMessage() { //outer c;lass method

class InnerSpace { //defining class in outter class method
public void receivingMessage() {

System.out.println("message send by eline is" +MessageComming);
}
}
}
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Core Java Interview Questions

class A { class B { psvm(String args[]) { } } } if the prg saved in A.java whats the o/p?

7 Answers   HCL, TCS,


How will you invoke any external process in java?

0 Answers  


what is difference between throw and throws in exception?

48 Answers   Spenco,


What are the 8 data types in java?

0 Answers  


Why does java does not support multiple inheritance? Explain

0 Answers  






Difference between prefix and postfix forms of the ++operator?

3 Answers  


what is the use of private constructor in core java?

3 Answers   OnMobile, Satyam, Yash Technologies,


Can we execute a program without main?

0 Answers  


What are the four integer types supported by java?

0 Answers  


What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?

0 Answers  


What is default exception handling in java?

0 Answers  


What is the size of arraylist in java?

0 Answers  


Categories