Creating Private Inner Classes in Separate Files

I sometimes find myself wanting to use private inner classes to do things, but then moving the classes to separate files and giving them package access just because I don't like having single large files.
Is there a way to create private inner classes on a class but just save them in another file?
Thanks,
John

For me, short file sizes usually make design structure
more clear. This can make maintenance easier. It can
also make browsing the code easier, even if you have a
good editor or IDE. It is also less intimadating
psychologically (for me, anyway) to work with a number
of small files, each one with a distinct purpose, than
it is to open up a monster, even if the monster does
represent a coherent design unit in some sense. I
think this psychological impact may be more important
than most people give it credit for.The psychological impact is lessened if you use an IDE like VisualAge (where only one method at a time is generally displayed) or use the "Show Source Of Selected Element Only" option in Eclipse.
It's one thing to say a method should be short and a class should have as few methods as possible. Those forces reduce complexity and ease maintenance. It's another to say a source file should be short. A source file is just a storage artifact; source code could be stored in a database without changing how the programmer interacts with it. The fact that the standard java compiler requires the implementation of nested classes to be stored inside the source file of their containing class is a minor inconvenience. Don't let it discourage you from using inner classes when they make sense. The design should not be driven by source file size considerations.
>
But you have added code only with the sole intent of
making a source file smaller. If Java had amechanism
for storing nested classes in other files youwouldn't
do this. My point below was that you shouldn't let
source file size override the decision to use anested
class.Why shouldn't I let it? There are plenty of
non-trivial benefits (the ones I gave above, for
starters) to working with smaller files.Because all of those benefits can be gained from using a decent IDE. Eclipse is free. It can show only the current method and it can collapse nested classes.
You say "If
Java had a mechanism...." Well, I could answer: It
does have such a mechanism, and that mechanism is
packages.Packages are not a mechanism for creating private inner classes in separate files. Eclipse has a mechanism for making the fact that they reside in the same source file a non-issue.
>>
I am not being cavalier. I have no argument, onlyan
opinion.Again, you are perfectly entitled to your opinion.
But if it is truly an opinion, and nothing more, why
bother telling me about it. You might as well post
your favorite color. It is the reasons for your
opinion that interest me, and you still have not
really given any.I have had lengthy arguments about the issue of method and class size. Like I said before, I prefer very small classes and methods. I also think the number of nested classes should be as small as possible. But I have no problem with large files. Files are just one way to organize source code. The size of the things in the files matters, not the files themselves.

Similar Messages

  • Private inner class and static private inner

    Hi,
    I understand the concept and usage of inner classes in general.
    When should we go for a private inner class and when for a static private inner class? I tried searching but it wasn't of much help.
    Basically I need to design a caching solution in which I need to timestamp the data object. After timestamping, data will be stored in a HashMap or some other collection. I'm planning to use a wrapper class (which is inner and private) which holds the data object and timestamp. I can make the program work by using either normal inner class or static inner class, however would like to know which is better in such case. Also If I can get some general guidelines as to when to use a staic inner class and when to use a normal inner class, it would help me.
    Thanks in advance.

    user1995721 wrote:
    When should we go for a private inner class and when for a static private inner class?
    I can make the program work by using either normal inner class or static inner class, however would like to know which is better
    If I can get some general guidelines as to when to use a static inner class and when to use a normal inner class, it would help me.Making the inner class static is helpful in that it limits visibility.
    If the inner class needs to access non-static fields or methods from the containing class instance
    the inner class has to be non-static.

  • Private inner class

    I have a private inner class , the methods and constructor of this inner class should be private or default ?Please explain me what is the right method and constructor access modifier I should use to private inner classes .

    paulcw wrote:
    I believe that if you make the constructor private, nothing can instantiate it.Not true for an inner class.
    Re the original question: I'm not sure it really matters here, but I've not seen a canonical answer to this.

  • Private inner classes

    I'm trying to complete a "turn the lightbulb on and off" program, but when I try to draw circle2 in the
    ButtonListener class I get an error message cannot find symbol. This is in reference to the Graphics
    variable "page" created in the paintComponent method below. Shouldn't the inner class, private or
    public inherit all data variables including objects from the parent class, in this case, the Bulb class? The code is below.
    By the way, this IS NOT a school assignment so any help would be appreciated. I'm just trying to learn
    this language.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Bulb extends JPanel
         private JButton push;
         private Circle circle, circle2;
         private final int DIAMETER = 100;
         private final int X = 10;
         private final int Y = 10;
         public Bulb()
              circle = new Circle(DIAMETER, Color.white, X,Y);
              circle2 = new Circle(DIAMETER, Color.yellow, X, Y); // to separate class
              push = new JButton("Turn on the Bulb");
              push.addActionListener(new ButtonListener());
              add(push);
              setPreferredSize(new Dimension(500, 500));
              setBackground(Color.black);
         public void paintComponent(Graphics page)
              super.paintComponent(page);
              circle.draw(page);
    private class ButtonListener implements ActionListener
              public void actionPerformed(ActionEvent event) //PROBLEM AREA. I GET ERROR MESSAGE STATING
    // "CANNOT FIND SYMBOL" IN REFERENCE TO VARIABLE "PAGE."
    // I THOUGHT THE INNER CLASS INHERITS ALL DATA FROM
    // PARENT CLASS SUCH AS "PAGE."
                   circle2.draw(page);
    }

    There are fields, which are associated with either a class or an object (and thus live in the heap in an object on the heap), and there are local variables, which are associated with methods and threads (i.e., a method invoked within a thread, and which thus live on the stack).
    They're not the same thing.
    You can't use a local variable in your paintComponent method in a different method.
    Anyway you're designing your class wrong. Think model-view-controller. You have the model: a bunch of state and possibly behavior that represents the thing being seen, modified, and displayed. You have the view, which is how you see the model. And you have the controller, which modifies the model.
    Your event handlers are part of the controller. They should change the model.
    Your paintComponent method is part of the view.
    So the event handlers should change some data, e.g., add a note that a circle should be displayed.
    Then your paintComponent method should look at the data and act accordingly -- e.g., see that there's a circle to be displayed, and display it.

  • Private inner class with private constructor

    I read that if constructor is public then you need a static method to create the object of that class.
    But in the following scenario why I am able to get the object of PrivateStuff whereas it has private constructor.
    I am messing with this concept.
    public class Test {
          public static void main(String[] args) {          
               Test t = new Test();
               PrivateStuff p = t.new PrivateStuff();
          private class PrivateStuff{
               private PrivateStuff(){
                    System.out.println("You stuff is very private");
    }

    A member (class, interface, field, or method) of a reference (class, interface, or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:
    * Otherwise, if the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor. [Java Language Specification|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.1]
    Your main method is within the body of the top level class, so the type (the inner class) and method are accessible.
    eg:
    class ImInTheSameSourceFileAsInnerAccessTest {
        public static void main(String[] args) {          
            InnerAccessTest t = new InnerAccessTest();
            InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    public class InnerAccessTest {
          public static void main(String[] args) {          
               InnerAccessTest t = new InnerAccessTest();
               PrivateStuff p = t.new PrivateStuff();
          private class PrivateStuff{
               private PrivateStuff(){
                    System.out.println("You stuff is very private");
    }Result:
    $ javac -d bin src/InnerAccessTest.java
    src/InnerAccessTest.java:4: InnerAccessTest.PrivateStuff has private access in InnerAccessTest
    InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    ^
    src/InnerAccessTest.java:4: InnerAccessTest.PrivateStuff has private access in InnerAccessTest
    InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    ^
    2 errors
    Edited by: pm_kirkham on 20-Jan-2009 10:54 added example of 'in the same source file'

  • Nested classes and separate files in Javadoc...

    Hello. I am writing an application, and it has several .java files, and some of the classes contained therein contain nested classes, for example
    ClassOne.java
    class ClassOne
    // stuff
       class innerClassOne
          //more stuff
    }ClassTwo.java
    class ClassTwo
    // stuff
       class innerClassTwo
          //more stuff
    }What I want to do is generate documentation like the online java documentation for my app, that is, documentation that will contain ALL the classes and nested classes involved, and link everything that comes in java already to the sun online java docs.
    I've figured out the -link command for javadoc, and I can make that work, but I've run into some other snags.
    1.) Javadoc isn't finding or documenting my nested classes, despite them being marked up. Google does not wish to help.
    2.) Some classes reference other classes of mine that aren't conatined in the same .java file, but do exist in their own .java files in the dame local directory. Javadoc does not like this, and gives errors.
    3.) Running javadoc on one file at a time overwrites the old file's documentation, thus I cannot seem to get an index.html javadoc file that links to all my classes, nor can I get the classes to link to each other.
    What do I need to do to fix these?

    So this means a nested static inner class CANNOT refer to its own instanced variables, like a normal static method, but CAN refer to its outer class instanced variables?No, it means that a static nested class cannot refer to instance variables of its enclosing class. Example:public class Foo {
        int i;
        static class Bar {
            int j = i; // WRONG! Bar class is static context
    }~

  • Compiler bug with generics and private inner classes

    There appears to be a bug in the sun java compiler. This problem was reported against eclipse and the developers their concluded that it must be a problem with javac.
    Idea also seems to compile the example below. I couldn't find a bug report in the sun bug database. Can somebody tell me if this is a bug in javac and if there is a bug report for it.
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422
    public class Foo <T>{
    private T myT;
    public T getT() {
    return myT;
    public void setT(T aT) {
    myT = aT;
    public class Bar extends Foo<Bar.Baz> {
    public static void main(String[] args) {
    Bar myBar = new Bar();
    myBar.setT(new Baz());
    System.out.println(myBar.getT().toString());
    private static class Baz {
    @Override
    public String toString() {
    return "Baz";
    Eclipse compiles and runs the code even though the Baz inner class is private.
    javac reports:
    Bar.java:1: Bar.Baz has private access in Bar
    public class Bar extends Foo<Bar.Baz>
    ^
    1 error

    As I said in my original post its not just eclipse that thinks the code snippet is compilable. IntelliJ Idea also parses it without complaining. I haven't looked at the java language spec but intuitively I see no reason why the code should not compile. I don't think eclipse submitting bug reports to sun has anything to do with courage. I would guess they just couldn't be bothered.

  • Private inner classes, should this compile:

    class Outer
    &nbsp&nbsp&nbsp&nbspclass InnerA;
    &nbsp&nbsp&nbsp&nbspclass InnerB;
    &nbsp&nbsp&nbsp&nbspclass InnerA
    &nbsp&nbsp&nbsp&nbsp{
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspInnerB* m_inner;
    &nbsp&nbsp&nbsp&nbsp};
    &nbsp&nbsp&nbsp&nbspclass InnerB
    &nbsp&nbsp&nbsp&nbsp{
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspInnerA* m_inner;
    &nbsp&nbsp&nbsp&nbsp};
    The Sun Studio 8 C++ compiler says that InnerB is not accessible from InnerA and vica-versa.
    However, both classes are members of the outer class and I would think that just like member functions, they should have access to all the declarations (prviate or not) in the outer class.
    Is the compiler correct to complain about this?
    Kind Regards,
    Dave.

    the current wording of the standard favours the Sun' s interpretation.
    gcc have gone with assuming that core language defect report 45 will be accepted which would allow this.
    see http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45 .
    /lib

  • Help: Factory Class using Inner Class and Private Constructor?

    The situation is as follows:
    I want a GamesCollection class that instantiates Game objects by looking up the information needed from a database. I would like to use Game outside of GamesCollection, but only have it instantiated by GamesCollection to ensure the game actually exist. Each Game object is linked to a database record. If a Game object exist, it must also exist in the database. Game objects can never be removed from the database.
    I thought about making the Game object an inner class of GamesCollection, but this means that Game class constructor is still visible outside. So what if I made Game constructor private? Well, now I can't create Game objects without a static method inside Game class (static Object factory).
    Basically what I need is a constructor for the inner Game class accessible to GamesCollection, but not to the rest of the world (including packages). Is there a way to do this?

    leesiulung wrote:
    As a second look, I was initially confused about your first implementation, but it now makes more sense.
    Let me make sure I understand this:
    - the interface is needed to make the class accessible outside the outer classBetter: it is necessary to have a type that is accessible outside of GameCollection -- what else could be the return type of instance?
    - the instance() method is the object factory
    - the private modifier for the inner class is to prevent outside classes to instantiate this objectRight.
    However, is a private inner class accessible in the outer class? Try it and see.
    How does this affect private/public modifiers on inner classes?Take about five minutes and write a few tests. That should answer any questions you may have.
    How do instantiate a GameImpl object? This basically goes back to the first question.Filling out the initial solution:
    public interface Game {
        String method();
    public class GameCollection {
        private static  class GameImpl implements Game {
            public String method() {
                return "GameImpl";
        public Game instance() {
            return new GameImpl();
        public static void main(String[] args) {
            GameCollection app = new GameCollection();
            Game game = app.instance();
            System.out.println(game.method());
    }Even if you were not interested in controlling game creation, defining interfaces for key concepts like Game is always going to be a good idea. Consider how you will write testing code, for example. How will you mock Game?

  • Problem creating inner class for JTable panel in a class for an application

    i want to create an inner class for a database application development.
    but there is occuring exceptions & errors.i want to retrieve data & enter data also from many tables in a database.i want an urgent help for this plz.

    http://forum.java.sun.com/thread.jsp?forum=57&thread=271752
    See this thread, please.

  • Problem with Outer and Inner Classes....or better way?

    Right now I'm trying to create an Inner class.
    My .java file compiles ok, and I create my jar file too.
    But when I try to instantiate the Inner class, it fails:
    java.lang.NoClassDefFoundError: com/myco/vlXML/vlXML$vlDocument.
    Here's the class code:
    public class vlXML{
        private ArrayList myDocList=new ArrayList(); //holds documents
        public vlXML(){
        private class vlDocument{
            public vlDocument(){
            //stuff goes here
        public vlDocument vlDOC(){
            return new vlDocument();
        public void addDocument(){
            vlXML xxx=new vlXML();
            vlDocument myDoc=xxx.vlDOC();
            myDocList.add(myDoc);
        public int getNumDocs(){
            return myDocList.size();
    }Then, from a jsp page, I call:
    vlXML junk1=new vlXML();
    junk1.addDocument();...and get the error...
    Can someone help me figure out why it's failing?
    Thanks....

    You nailed it - thanks....(duh!)
    While I have your attention, if you don't mind, I have another question.
    I'm creating a Class (outer) that allows my users to write a specific XML file (according to my own schema).
    Within the XML file, they can have multiple instances of certain tags, like "Document". "Document"s can have multiple fields.
    Since I don't know how many "Documents" they may want, I was planning on using an Inner Class of "Document", and then simply letting them "add" as many as necessary (thus the original code posted here).
    Does that seem like an efficient (logical/reasonable) methodology,
    or is there there something better?
    Thanks Again...

  • Subclassing and inner classes

    Hi there,
    I have an existing class "A", supplied by a third party, that contains a private inner class "I".
    I have subclassed "A" to a new class "B" to add new functionality, and I also want to replace the inner class "I" with new behaviour. The inner class "I" is invoked by methods within "A" that I have not overridden in "B". Replacing "I" appears to be impossible under these circumstances.
    My initial experiment was to create a new inner class "I" within "B" with the same name and signature as the "I" defined within "A", so...
    Class B extends A {
    private class I {}
    The code that invokes "I" is still within "A" and so my version of the "I" class is ignored, and the original "I" is invoked instead.
    Let's be clear about this, I am not surprised by this behaviour, I'm just wondering if there is any way I can get my "I" invoked by the methods in "A". If that is indeed impossible I will have to write new methods in "B" that override the invoking methods in "A".
    I did a search on the forums using the title I gave this topic, and got some fairly close hits, but nothing seemed to quite answer my question.
    Hope that all made sense. Thanks for any help.
    Regards,
    Tim

    When a class is compiled, all the references are resolved. So in the 'A' class file, a call to method someMethod() in inner class I is resolved as
    some.package.A$I.someMethod()
    Short of replacing the A$I class file, I don't know what you can do. (I think)

  • JSP Inner class generates IllegalAccess Error

    I created an inner class inside of a JSP file. Unfortunately, Weblogic 5.1.0
              compiles the inner class as private. So I got an IllegalAccessError. Is
              there a way to use inner classes in JSP files?
              Thank you.
              - Remington
              Here is my code:
              <%
              Object obj = new Object()
              public int hashCode()
              return 100;
              out.println( "obj: " + obj.hashCode() );
              %>
              Error messages:
              Wed Jan 31 17:23:38 PST 2001:<E> <ServletContext-General> Servlet failed
              with Exception
              java.lang.IllegalAccessError: try to access class
              jsp_servlet/_test/_test01$1 from class jsp_servlet/_test/_test01
              at jsp_servlet._test._test01._jspService(_test01.java:66)
              at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
              at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              :105)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:742)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:686)
              at
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
              Manager.java:247)
              at
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)
              at
              weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled
              Code)
              

    Works ok with sp8.
              Remington Li <[email protected]> wrote:
              > I created an inner class inside of a JSP file. Unfortunately, Weblogic 5.1.0
              > compiles the inner class as private. So I got an IllegalAccessError. Is
              > there a way to use inner classes in JSP files?
              > Thank you.
              > - Remington
              > Here is my code:
              > <%
              > Object obj = new Object()
              > {
              > public int hashCode()
              > {
              > return 100;
              > }
              > };
              > out.println( "obj: " + obj.hashCode() );
              > %>
              > Error messages:
              > Wed Jan 31 17:23:38 PST 2001:<E> <ServletContext-General> Servlet failed
              > with Exception
              > java.lang.IllegalAccessError: try to access class
              > jsp_servlet/_test/_test01$1 from class jsp_servlet/_test/_test01
              > at jsp_servlet._test._test01._jspService(_test01.java:66)
              > at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
              > at
              > weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              > :105)
              > at
              > weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              > l.java:742)
              > at
              > weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              > l.java:686)
              > at
              > weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
              > Manager.java:247)
              > at
              > weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)
              > at
              > weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled
              > Code)
              Dimitri
              

  • Inner classes in ABAP

    Hello!
    Is it possible to declare inner classes, that is, classes within classes in ABAP? If yes, please provide example.
    Thanks!
    Kind regards,
    Igor

    > No. I need a class to be declared within a class, or
    > even within a method in order to make it visible only
    > to the containing class (or method).
    You cannot <b><i>nest</i></b> class declarations, but there <b><u>happens to be</u></b> a way of implementing the functionality you desire, though too tedious to be useful practically. You can use a combination of a <b>"CREATE PRIVATE"</b> class and the <b>Friendship</b> idea to do this. A quick and dirty example is :
    REPORT  zootest.
    CLASS lcl_test_outer DEFINITION DEFERRED.
    *       CLASS lcl_test_inner DEFINITION
    CLASS lcl_test_inner
                     DEFINITION CREATE PRIVATE
                     FRIENDS lcl_test_outer.
      PUBLIC SECTION.
        DATA: test.
    ENDCLASS.              
    *       CLASS lcl_test_outer DEFINITION
    CLASS lcl_test_outer DEFINITION.
      PUBLIC SECTION.
        METHODS: test_inst.
    ENDCLASS.                  
    *       CLASS lcl_test_outer IMPLEMENTATION
    CLASS lcl_test_outer IMPLEMENTATION.
      METHOD test_inst.
        DATA: ref1 TYPE REF TO lcl_test_inner.
        CREATE OBJECT ref1.
      ENDMETHOD.
    ENDCLASS.
    DATA: ref1 TYPE REF TO lcl_test_inner,
          ref2 TYPE REF TO lcl_test_outer.
    START-OF-SELECTION.
      CREATE OBJECT ref2.
    Crude, but it can be refined further, but I hope this helps
    Regards,
    Dushyant Shetty

  • Doubt in inner classes

    public class Outer
               public static void main(String argv[])
                         Outer o=new Outer(); //1                    
                         Inner i =o.new Inner(); //2
                         //Inner i =new Inner();  //3
         i.showName();   
             public      class Inner{   
                    void showName()
            System.out.println("hi");            
          }//End of Inner class
    }I have few doubt regrd the above program..
    1)when i create an inner class instance as in line 3,..Iam having an err like
    non-static variable this cannot be referenced from a static context.. Bcas Inner is a non static member of class Outer it cant be referred without an instance of Outer as in line 2.. But my doubt is why it doesnt give such error (of static context issue) in the case of line 1...its a silly dbt but iam confused ...
    2..Can we refer the inner class without outer class like in line 2., I have used
    Inner without Outer ..is this ok... or shuld we use as
    Outer.Inner i =o.new Inner(); //2
    3)In the above line We r associating the instance of inner class with the instance of outer class and the type of inner class with the type of outer class (Outer.Inner )..wht does this mean..
    can anyone pls help me understand this..
    thnx.
    mysha..

    public class Outer
    public static void main(String argv[])
    Outer o=new Outer(); //1
    er o=new Outer(); //1                    
    Inner i =o.new Inner(); //2
    //Inner i =new Inner();  //3
         i.showName();   
    public      class Inner{   
    void showName()
            System.out.println("hi");            
    }//End of Inner class
    }I have few doubt regrd the above program..
    1)when i create an inner class instance as in line
    3,..Iam having an err like
    non-static variable this cannot be referenced from a
    static context.. Bcas Inner is a non static member of
    class Outer it cant be referred without an instance
    of Outer as in line 2.. But my doubt is why it doesnt
    give such error (of static context issue) in the case
    of line 1...its a silly dbt but iam confused ...
    Static methods of a class exist as soon as Java loads the class. Regular, or non-static, methods of a class belong to an object and only come into existence after you create an object of the class. Regular methods are called by an object. Static members are called using the class name.
    Now, examine this simple program:
    class Apple
         private String color;
         public Apple(String color)
              this.color = color;
         public void show()
              System.out.println("apple color: " + color);
         public static void greeting()
              System.out.println("Hello from the Apple class.");
    public class  Demo
         public static void main(String[] args)
              Apple.greeting();  //1
              Apple a = new Apple("red");  //2
    }After the Apple class loads, any static methods in the class exist. Since greeting() is a static method of the Apple class, it can be called in line 1 before any Apple objects exist. But, what about line 2? How can the Apple constructor with the String parameter, which is a method in the Apple class, be called? The constructor isn't declared as a static, so it shouldn't exist in that regard, and no objects of the class exist. So, when and how did the constructor come into existence. That seems to be the question you're struggling with. I think the answer is: a constructor sort of acts like a static method. In order to be able to call a constructor, the constructor must exist as soon as the class loads and before any objects exist. The result is, you can call a constructor at any time.
    I think your example is similar to my example, but you only have one class:
    public class Outer
    public static void main(String argv[])
    Outer o=new Outer(); //1
    }After Java loads Outer, any static methods in Outer exist. Since main() is a static method, it exists. Subsequently, java calls the static main() method to begin execution of your program. In line 1, you call the default constructor for Outer. The default constructor isn't static, so it shouldn't exist, but just like the constructor in my example above, the default constructor acts like a static method, and therefore you can call it without getting an error.
    Inner i =o.new Inner(); //2
    2..Can we refer the inner class without outer class
    like in line 2., I have used
    Inner without Outer ..is this ok... or shuld we use
    as
    Outer.Inner i =o.new Inner(); //2
    I'm not sure what the difference is. In both cases you end up with an object that was created with the expression:
    o.new Inner()
    you just have a different type for your object, i.e. Outer.Inner versus Inner.
    3)In the above line We r associating the instance of
    inner class with the instance of outer class and the
    type of inner class with the type of outer class
    (Outer.Inner )..wht does this mean..
    can anyone pls help me understand this..
    I think you said it: it means you have an Inner object that is "associated" with an Outer object. Like any other regular member in the Outer class, Inner can refer to any members of Outer. (A static member of Outer can't refer to regular members of Outer because static members exist before any objects exist, and when no objects exist, the regular members don't exist.) That means an Outer object must exist before you can create an Inner object.

Maybe you are looking for

  • Track Changes log of a specified Standard Text?

    Hello Experts, Am looking to develop a report (change log report) for standard texts, for example, (pls. note all input parameters of this standard text are same) Yesterday the user entered the standard text as   This is yesterdays standard text And

  • How can I sync my new iPhone to iTunes without a computer.

    I need to get my music on phone but it only shows in iTunes not in the music player. How do I do that without computer

  • 5.1 for Shows

    In my search I found an article someone posted regarding Dolby Digital sound for movies purchased in the iTunes store but no mention of shows. I understand some won't be but more recent shows that are broadcast in 5.1 like Lost, 24, etc. Thanks in ad

  • Date Sort inside For Each

    Hi I am trying to date sort inside for each but it is not working i am using below code <?for-each:G_3?><?sort:BEG_DT;'ascending';data-type='text'?>BEG_DT END_DT <?end for-each?> Can any one please let me know how to solve this? Thanks in Advance Hav

  • VS2012: v110_xp 11.0\VC\include\sal.h __useHeader redefinition when editing resources

    We have a project that we have brought forward from VS 8.0 through VS 10.0 to VS 11.0 and wish to maintain Windows XP support so we have the Platform Toolset on v110_xp. Every time I attempt to edit a resource by expanding the PROJ.rc node in the Res