• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inner or rather nested Classes - The mystery

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clarification 1:

A nested class is any class that is declared within the body of another class or interface.
An inner class is a nested class that is not static.

So any class declared within a class is called nested.But usually v call class inside another class as inner classes.

In exam how should v identify a class inside another class, as nested or inner??

Clarification 2:

A local class is a inner class because it shared the same relationship with outer class instance.
The difference between local class and inner class is local class cannot be instantiated outside method.


Clarification 3:

An anonymous class is always a local class or it can be declared as value to a instance varaible.

A local class is always a named class -- is this true? even anonymous classes can b local rt?

Clarification 4:

1.A inner class can be extended only if the outer class is extended.
2. A inner class can extend outer class itself.

Are these statments right.

I found these statements in Dan Chisholm's Questions and have added my understanding as well

Plz clarify them.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please find the detailed answer for clarification below:

Clarification 1:

If you define a class within another class then it is called a nested class.

class OuterClass {
...
class InnerClass {
...
}
}
It is come with two flavors. i) A nested class can be declared static (or not). A static nested class is called static nested class. ii)A nonstatic nested class is called an inner class.
class OuterClass {
...
static class StaticNestedClass {
...
}
class InnerClass {
...
}
}

So with the help of keyword static you can distinguish between static nested or inner class.

Clarification 2:

As the name suggest for local class (within the method) the scope of that class in limited within the method.
Local classes are declared within a block of code and are visible only within that block, just as any other method variable.

Clarification 3:

You can declare an inner class without naming it, called an anonymous class or you can say an anonymous class is a local class that has no name.
An anonymous class is generally used inside an expression and it does not have member scope, since it isn't visible to the enclosing class. Anonymous classes can make code difficult to read.
If you want to use an anonymous inner class, but it's too long to include inline, you can use a local class. A local class is like a named anonymous class. Typically, a local class is declared within a method or to initialize a field and, like an anonymous class, it also does not have member scope.

Clarification 4:

What exactly do you want for this clarification?
It clearly stated that �An inner class can be extended only if the outer class is extended.� means to extent an inner class you are bound to extend outer class.

Please let me know if you find anything wrong!!

Regards,
Sumit Jain
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic