Results 1 to 4 of 4
  1. #1
    Gobi is offline Member
    Join Date
    Jun 2011
    Posts
    13
    Rep Power
    0

    Default Why cant we have static outer class

    Hi everyone ,

    wanna know why cant we have static outer class ..
    checkout the below code snippet .If I declare outer class as static then compiler throws an error .. the same I have did for inner class but no issues there.

    Java Code:
    static class outerclass{
    	
    	static class innerclass{
    		
    		public static int data ; 
    		
    	}
    	
    	public static int outdata;
    	
    }

    I googled it quickly for this queston ,unfortunately I couldn't find any relevent post . hence I started new thread .

  2. #2
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: Why cant we have static outer class

    What do you think will be a static outer class compared to a normal class? What effort do you get from making an outer class static?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Why cant we have static outer class

    Quote Originally Posted by Gobi View Post
    I googled it quickly for this queston ,unfortunately I couldn't find any relevent post . hence I started new thread .
    The place to look for such stuff is in the language spec: Chapter*8.*Classes

    As noctarius implied, the static keyword doesn't make any sense at all in the declaration of a top-level class.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Gobi is offline Member
    Join Date
    Jun 2011
    Posts
    13
    Rep Power
    0

    Default Re: Why cant we have static outer class

    Yes , you are right ... Thanks to both of you .

Similar Threads

  1. Replies: 5
    Last Post: 12-18-2011, 04:06 AM
  2. Inner or outer class
    By Dipke in forum New To Java
    Replies: 2
    Last Post: 07-22-2011, 01:57 PM
  3. Replies: 0
    Last Post: 02-17-2008, 09:03 AM
  4. Replies: 0
    Last Post: 02-17-2008, 09:01 AM
  5. Inner class accessing outer class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-17-2008, 08:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •