• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

static members and inheritance

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following two examples -

Example 1:

Example 2:

All of the static member resolution is done by the compiler. Thus, there is no scope of runtime polymorphism with static member of a class.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Unmesh Chowdhury wrote:
All of the static member resolution is done by the compiler. Thus, there is no scope of runtime polymorphism with static member of a class.



Sounds about right to me.
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Polymorphism is only for objects, not for classes. No Polymorphism => No virtual method invocations. static members are bounded at compile time(Early binding).
 
Unmesh Chowdhury
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dear Abimaran Kugathasan. How do you can get object without any class? A class is the template of its objects and an object is constructed as it is defined in it's class.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Unmesh Chowdhury wrote:Hi Dear Abimaran Kugathasan. How do you can get object without any class? A class is the template of its objects and an object is constructed as it is defined in it's class.



Due to the combination of the class hierarchy and the fact that a class can implement many different interfaces, a single object in Java can be treated as many different types. And In your case, the ultimate goal of the class is to create object.
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simply..
the object reference types decide which static methods or the static variables to be used
and another point I want to clear is
inherited methods are NOT copied (let the experts comment more on this) they are same as those in superclass and
they are not actually copied into subclass
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Kharkar wrote:Simply..
the object reference types decide which static methods or the static variables to be used


I would disagree as objects have nothing to do with static methods or variables. What matters is the class, in this example the class type of the variable, not the object it refers to (even if the variable refers to null). Regardless, one shouldn't try to dereference static variables or methods with variables but rather with classes to avoid this confusion.
 
Unmesh Chowdhury
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Abimaran Kugathasan, not only in my case, in every case, the ultimate goal of the class is to create object. It is true that in Java an object can be of different types according to the class hierarchy and interfaces. In the case of interface, an object will be an interface type, if it's class implements that interface. In fact, if a class does not implement a particular interface then the objects of that class will not be of that particular interface type. Thus, a class is the blueprint of an object and an object is just a run time instance of a class.

Thus, there is no scope of runtime polymorphism with static member of a class



The above statement means that, it will be true when objects are created from this class, that is, it will be a characteristics of this class objects. And my thought was that, this implicit meaning is cleared to every folks like you.
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@pete
I wanted to say Reference type of the variable (wanted to say what you have said )
thank you for correcting English mistake
have a nice time to all
 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic