Results 1 to 3 of 3
  1. #1
    kashyapkeshav is offline Member
    Join Date
    Aug 2012
    Posts
    10
    Rep Power
    0

    Default Can the class be instantiated with the static keyword ?

    Can the class be instantiated with the static keyword ?
    eg :
    static class c1(){
    }

    can thisbe done? am confused with this and the memory mapping with non static stuff's please help

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default Re: Can the class be instantiated with the static keyword ?

    No.
    That wouldn't be a class clause. It more resembles a method.
    A method that is static, returns a "class" object and is called c1.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Can the class be instantiated with the static keyword ?

    A static class has to be a class nested in the scope of another class (otherwise the 'static' qualification is forbidden). You don't need an object of the enclosing class to create an object of the (static) nested class; if the nested class weren't static you would need an object of the outer class to create an oject of the nested (inner) class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Using variables from a non-instantiated class
    By Skater901 in forum New To Java
    Replies: 4
    Last Post: 05-19-2012, 12:43 PM
  2. Class can't be instantiated.
    By 3maksim in forum Java Applets
    Replies: 12
    Last Post: 01-25-2012, 05:23 AM
  3. static keyword
    By lala in forum New To Java
    Replies: 19
    Last Post: 01-11-2011, 08:06 PM
  4. class is abstract; cannot be instantiated
    By Jamison5213 in forum New To Java
    Replies: 3
    Last Post: 04-25-2010, 09:16 PM
  5. use of static keyword
    By venkatallu in forum New To Java
    Replies: 2
    Last Post: 06-25-2009, 07:53 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
  •