Results 1 to 7 of 7
  1. #1
    jatinrai199 is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Cool static functions

    we know that we can access only static data members in static functions.

    but can we declare and define static data members in static functions..???
    :confused:

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

    Default

    Quote Originally Posted by jatinrai199 View Post
    we know that we can access only static data members in static functions.

    but can we declare and define static data members in static functions..???
    :confused:
    No,you could've tried it and noticed that the compiler will protest against it.

    kind regards,

    Jos

  3. #3
    jatinrai199 is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Cool

    ok i got it it will give error , i know that but why we can't define and declare static data member in static functions ?????????

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

    Default

    Quote Originally Posted by jatinrai199 View Post
    ok i got it it will give error , i know that but why we can't define and declare static data member in static functions ?????????
    Because that's the way the language was defined.

    kind regards,

    Jos

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by jatinrai199 View Post
    ok i got it it will give error , i know that but why we can't define and declare static data member in static functions ?????????
    That makes no sense. All fields defined within a method are local to the method, whether the method be static or instance.

  6. #6
    kjv007 is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by jatinrai199 View Post
    ok i got it it will give error , i know that but why we can't define and declare static data member in static functions ?????????

    correct me if i'm wrong, in java declaring a variable with static will make it a class variable; we cannot put a class variable inside a function because it suppose to be a variable for all the members of the class.

  7. #7
    jatinrai199 is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default

    hmm it make sense....
    i thnk u r rht ..
    stati cmake a variable a class level varialble..

Similar Threads

  1. Replies: 4
    Last Post: 05-12-2010, 11:05 AM
  2. Replies: 3
    Last Post: 02-11-2010, 09:59 AM
  3. Non-Static method in static context error
    By wizmang in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 08:51 AM
  4. Replies: 1
    Last Post: 08-07-2007, 05:05 AM
  5. Replies: 1
    Last Post: 08-01-2007, 09:25 PM

Posting Permissions

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