• 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

How do you refrence an inner class that inside a method?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actualy I have 2 questions.
1. What the point of innerclass inside of a methed?
Why would I ever do this?
2. How do I create an object of that type outside the method?
From main for example.
Outer.inner doesn't work in this situation.
Thanks in advance.
Kourosh
 
Ranch Hand
Posts: 103
Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Kouresh,
1> The point in defining an inner class inside a method is to get the specific behavior of an interface by extending it, and restricting that behavior to only that method.
2> U can not create an object of the class which is diclared inside the method becoz the scope of the class is inside that method only.


------------------
Graaaasp the Concepts and Graaaab SCJP. :Anil Kollur:
 
Anil Kollur
Ranch Hand
Posts: 103
Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Kouresh,
1> The point in defining an inner class inside a method is to get the specific behavior of an interface or an abstract class by extending it, and restricting that behavior to only that method.
2> U can not create an object of the class which is diclared inside the method becoz the scope of the class is inside that method only.
Please read Thinking in Java and about polymorphism.

[This message has been edited by Anil Kollur (edited November 09, 2000).]
 
Kourosh Keshavarzi
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anir,
I still can't imagine ever using this in real life code but
What you said makes since because it increase what you can get out of implementing an interface.
So you normaly wouldn't declare an inner class in a method and
then use it right there and then.
And you can only create an instance of the class
while inside the method or a method that overides or implements
the method.
Did I get more out of what you said than there was?
I understand all the rules I guess I just havn't seen any examples that implement this idea. Hopefuly I',ll find it in the book you recommended. I'll check it out.
For now thanks.
Kourosh Keshavarzi
reply
    Bookmark Topic Watch Topic
  • New Topic