File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to call inner class method from static main() method - No static class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to call inner class method from static main() method - No static class" Watch "How to call inner class method from static main() method - No static class" New topic
Author

How to call inner class method from static main() method - No static class

agilemanoj kumar
Ranch Hand

Joined: Mar 07, 2008
Posts: 70
Hi,
I have an inner class(It is not a static class, just plain inner class) inside an outer class given below:



I would want to call display() method from static void main() method.
Coditions:
1. Do not insert/delete any code written above.
2. We have a flexibility to add any number of lines in main() method

How can we do that?

--
Thanks,
Manoj Kumar


Manoj Kumar
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

Homework?

I'll give you a hint: an instance of a non-static inner class can only exist in the context of an instance of the containing class.

edit I'll also give you a word of advice: By convention, class names start with an uppercase letter.


luck, db
There are no new questions, but there may be new answers.
agilemanoj kumar
Ranch Hand

Joined: Mar 07, 2008
Posts: 70


I tried adding these two statements in main() method. But, it is giving me compile time error. What am I doing wrong??

--
Thanks,
Manoj Kumar
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

create inner class object as
then call inner class method


Life is easy because we write the source code.....
agilemanoj kumar
Ranch Hand

Joined: Mar 07, 2008
Posts: 70
Thank you very much
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

If you need to retain references to both the instances of outerClass and innerClass:Note that since the code is within the class scope of outerClass, you don't need to fully qualify the name of innerClass. Pramod's code can also be written as
 
 
subject: How to call inner class method from static main() method - No static class
 
Similar Threads
Anonymous Inner Class
question on annonymous inner class
Nested classes - Series of doubts
Anonymous inner class
INNER CLASS AGAIN~~~! So terrible