what is inner class?
Answers were Sorted based on User's Feedback
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 |
Answer / varsha vilas kalebag
inner classes has right to excess members of outer classes
Is This Answer Correct ? | 11 Yes | 1 No |
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 |
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 |
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 |
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 |
What is boolean false?
4.1 Supply contracts (in the form of comments specifying pre- and post conditions) for the enqueue() method of the LinkedQueue class given in the Appendix. (2) 4.2 Let Thing be a class which is capable of cloning objects, and consider the code fragment: Thing thing1 = new Thing(); //(1) Thing thing2 = thing1; //(2) Thing thing3 = (Thing) thing1.clone(); //(3) Explain how the objects thing2 and thing3 differ from each other after execution of the statements. (
Is alive in java?
Can we able to pass objects as an arguments in java?
What is the difference between jsp and servlet?
What are the types of classes in java?
How many decimal places is a double?
What is Remote Interface ?
What is singleton service?
How do you clear a method in java?
java is fullu object oriented or pure? why?
What is instance example?