This discussion is archived
12 Replies Latest reply: Jan 22, 2013 3:13 PM by baftos RSS

static !!!!

986268 Newbie
Currently Being Moderated
Why top level class cant be "static"???
  • 1. Re: static !!!!
    EJP Guru
    Currently Being Moderated
    Because it doesn't mean anything, or rather it doesn't add any meaning. It adds a meaning to nested classes.
  • 2. Re: static !!!!
    986268 Newbie
    Currently Being Moderated
    can u please elaborate??? i have also read the same in some java books.. but none of the books explain their sayings. please provide an explanation in terms of the "static" keyword in java..

    I know also that static means it belong to class.. so for inner class we can say static because it satisfies that it belongs to class. But if we put static before a top level class it arises a question "which class it belongs to??"...That is why compiler does not allow this meaningless things... This is my concept.. Am i right??
  • 3. Re: static !!!!
    EJP Guru
    Currently Being Moderated
    That's right. Ask yourself what it would mean that isn't already true. Answer: nothing.
  • 4. Re: static !!!!
    825299 Newbie
    Currently Being Moderated
    If you keep top level class as static
    1. The class will be useless.
    2. This class will not support any further inheritance.
    3. Even if you create any instance of the class, you will get the same state and behaviour.
  • 5. Re: static !!!!
    Kayaman Guru
    Currently Being Moderated
    Raja wrote:
    If you keep top level class as static
    1. The class will be useless.
    2. This class will not support any further inheritance.
    3. Even if you create any instance of the class, you will get the same state and behaviour.
    Please don't confuse people with wrong answers. It was already concluded that you can't have static top level classes.
  • 6. Re: static !!!!
    825299 Newbie
    Currently Being Moderated
    Can you please tell us what wrong with my answer?
  • 7. Re: static !!!!
    Kayaman Guru
    Currently Being Moderated
    Raja wrote:
    Can you please tell us what wrong with my answer?
    All your points are wrong, because a top level class cannot be static.

    You only invented 3 "reasons", but they're only your inventions:
    1. The class will be useless.
    If a static top level class was allowed, it certainly wouldn't be useless. Why would the designers have included it?
    2. This class will not support any further inheritance.
    Why not? Did you decide this?
    3. Even if you create any instance of the class, you will get the same state and behaviour.
    How did you figure that? Do all static inner classes have the same state? No.
  • 8. Re: static !!!!
    EJP Guru
    Currently Being Moderated
    Raja wrote:
    Can you please tell us what wrong with my answer?
    Certainly.
    If you keep top level class as static
    1. The class will be useless.
    Wrong. Static classes are not useless in any context.
    2. This class will not support any further inheritance.
    Wrong again. You seem to be thinking of 'final'.
    3. Even if you create any instance of the class, you will get the same state and behaviour.
    Wrong for the third time. 'static class' does not mean that in any context.

    In all three cases, it would only mean that if that's what it meant, which is a circular argument. As the reality is that it doesn't mean anything at all, let alone any of your propositions, your propositions are all futile.

    In summary, your answer was wrong in all three numbered items. In addition, the question had already been answered, correctly. So you clearly hadn't read the entire thread before posting. Instead you just posted your own uninformed and inaccurate guesswork.

    So, 'what was wrong with your answer' was 'everything'.

    Does that answer your question?
  • 9. Re: static !!!!
    gimbal2 Guru
    Currently Being Moderated
    EJP wrote:
    1. The class will be useless.
    Wrong. Static classes are not useless in any context.
    Unless they are not actually used.

    \*runs away\*
  • 10. Re: static !!!!
    986268 Newbie
    Currently Being Moderated
    If a top level class was allowed to have a static keyword before its name then how one could say that it would not be inherited. I don't know.. Or why people are talking about useless..
    Compiler is not allowing us to put static keyword. I think that is up to the design. That's how compiler works. It has not the instruction to allow it . That's it.
    I think if we discuss everything in terms of "static " meaning then it would be simple.. Otherwise we need an explanation from the JAVA team..
  • 11. Re: static !!!!
    EJP Guru
    Currently Being Moderated
    ... I don't know.. Or why people are talking about useless..
    Only one person said anything would be useless, and that was in an entirely useless reply. Don't fret about it. It's been rebutted, twice. We don't need to go on about it forever.
    Otherwise we need an explanation from the JAVA team.
    Explanation of what? There is nothing for them to explain. 'static' is redundant at the outer level so it isn't allowed. Period.
  • 12. Re: static !!!!
    baftos Expert
    Currently Being Moderated
    so for inner class we can say static because...
    I don't want to sound pedantic, even if I know I do, but the right terminology is "static nested classes".
    See here, right at the begining, "Terminology": http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points