Results 1 to 10 of 10
  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default Why don't our classes inherit static methods of the Object class?

    Every class is a descendant, direct or indirect, of the Object class. Every class you use or write inherits the instance methods of Object.
    Source.

    Why only instance methods? Why not static methods as well?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Why don't our classes inherit static methods of the Object class?

    It doesn't say "only the instance methods", so is not incorrect, merely incomplete.
    From the JLS:
    A class C inherits from its direct superclass all concrete methods m (both static and instance) of the superclass for which all of the following are true:

    m is a member of the direct superclass of C.

    m is public, protected, or declared with package access in the same package as C.

    No method declared in C has a signature that is a subsignature (8.4.2) of the signature of m.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Why don't our classes inherit static methods of the Object class?

    Actually, since Object doesn't have any visible static methods then the point is moot.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default Re: Why don't our classes inherit static methods of the Object class?

    Actually, since Object doesn't have any visible static methods then the point is moot.
    Oh yes, I just saw that. Thank you (but I do still think that they way they have said it does present some confusion).

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Why don't our classes inherit static methods of the Object class?

    Quote Originally Posted by Zarah View Post
    Oh yes, I just saw that. Thank you (but I do still think that they way they have said it does present some confusion).
    I can see how one might infer that only instance methods may be inherited. But they did said it in the context of also overriding those methods:

    "Every class you use or write inherits the instance methods of Object. You need not use any of these methods, but, if you choose to do so, you may need to override them with code that is specific to your class."

    You can't override a superclass' static methods. You can only hide them.

    If you want to get more specific insight into Java and its constructs, I suggest you check out the JLS.
    Here is a link -> Java SE Specifications

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default Re: Why don't our classes inherit static methods of the Object class?

    But they did said it in the context of also overriding those methods... You can't override a superclass' static methods. You can only hide them.
    I agree that the likely reasons for only mentioning the instance methods are that they are discussing the class Object and the Object class does not have any static methods (reference); and also to set the context for saying that we can override the (instance) methods of Object in our classes.

    If you want to get more specific insight into Java and its constructs, I suggest you check out the JLS.
    Thank you very much for the advice, but I am not sure what you mean by 'more specific insight', because the tutorials I am reading do define and describe (and include examples etc.) most of the constructs (I think), though I do keep forgetting and mixing up but hopefully that will improve once I start practicing. I follow those tutorials because I feel that once I have understood the important chapters (classes and objects, inheritance and interfaces, strings and numbers, basic I/O, exception handling, concurrency, JDBC), I can feel secure that I have understood the fundamentals of Java.

    Then I can start writing small apps to solve my problems.

    But from now on if I am not sure of what some construct means or implies, I will look into the JLS. Thank you for the link.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Why don't our classes inherit static methods of the Object class?

    The tutorials help with actually writing Java code.
    The JLS explains how the language itself actually works, under the hood so-to-speak.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default Re: Why don't our classes inherit static methods of the Object class?

    The JLS explains how the language itself actually works, under the hood so-to-speak.
    Oh. Then I'll be looking into the JLS more often. Thank you.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Why don't our classes inherit static methods of the Object class?

    Quote Originally Posted by Zarah View Post
    Oh. Then I'll be looking into the JLS more often. Thank you.
    It's not an easy read. It's not intended to be.
    It's a specification.
    I've only read bits as I've needed, and that's mostly in online discussions of definitions...like the above.
    :)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default Re: Why don't our classes inherit static methods of the Object class?

    Again I jumped to a conclusion (probably too soon) that JLS must be a place where rules are written in the most clear, logical and direct way and when I need to quickly know, e.g. how inheritance works - what is allowed and what is not, I will get the information from JLS. I will have to try to read on some topic some day to reach a better conclusion.

    But I'll take your word for it not being an easy read and I'll beware.. =)

    Edit:

    Just opened page 208 of JLS8 document (on Class Members), and my mind has told me a 'No' after the first glance. Too many cross-references. I will open it to clarify one confusion and it will lead to 12 new confusions.
    Last edited by Zarah; 03-02-2016 at 04:45 PM.

Similar Threads

  1. Replies: 1
    Last Post: 07-12-2012, 11:04 PM
  2. Replies: 2
    Last Post: 07-12-2012, 11:04 PM
  3. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  4. 'Class' Object and calling Static Methods?
    By mikeiz404 in forum Advanced Java
    Replies: 3
    Last Post: 01-24-2009, 12:58 PM
  5. 'Class' Object and calling Static Methods?
    By mikeiz404 in forum New To Java
    Replies: 2
    Last Post: 01-24-2009, 05:10 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
  •