File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
agilemanoj kumar
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Darryl Burke
Bartender
Posts: 5116
11
Java Netbeans IDE Opera
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
agilemanoj kumar
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create inner class object as
then call inner class method
 
agilemanoj kumar
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
Darryl Burke
Bartender
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic