2 Replies Latest reply: Jan 16, 2009 12:54 AM by 843785 RSS

    Why files with no public classes have no naming restrictions ?

    843785
      As i know a file with a public class ,uch have the same name as the class name but the files with no public classes have no naming restrictions and then how we can access these classes ?
        • 1. Re: Why files with no public classes have no naming restrictions ?
          791266
          Ravi784 wrote:
          As i know a file with a public class ,uch have the same name as the class name but the files with no public classes have no naming restrictions and then how we can access these classes ?
          In the normal way.

          Why are you posting all these stupid questions? Are you trying to solve your homework? We aren't here to solve it for you.

          Kaj
          • 2. Re: Why files with no public classes have no naming restrictions ?
            843785
            but the files with no public classes have no naming restrictions and then how we can access these classes ?
            You can access a class in a files with no public classes have no naming restrictions by just creating their object.
            Here is the code you can run.

            File: NonPublic.java
            /**
             * @(#)NonPublic.java
             *
             *
             * @author Gagan Ichake
             * @version 1.00 2009/1/15
             */
            
            
            class NotAsFileName{
            
                
                 void baz()
                 {
                      System.out.println("I am in NonPublic class.");
                 }
                
            }
            File: AccessNonPublic.java
            /**
             * @(#)AccessNonPublic.java
             *
             *
             * @author Gagan Ichake
             * @version 1.00 2009/1/15
             */
            
            
            public class AccessNonPublic {
            
            
                    public static void main(String []arg)
                 {
                      NotAsFileName nafn = new NotAsFileName();
                      nafn.baz();
                 }
                
            }
            Edited by: Ggn on Jan 15, 2009 10:53 PM