• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Static Doubt

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi All,

In above code how subclass Minor can use static variable y,variable y belongs to super class Uber.How subclass can inherit it.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by maredu ramesh:
...how subclass Minor can use static variable y,variable y belongs to super class Uber.How subclass can inherit it.


Welcome to JavaRanch!

The keyword "static" does not prevent inheritance.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI. Static Variable values are avialable to all the instances of its class and its subclass.So Y is available to subclass constructor. And finally Output is 9.
 
maredu ramesh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


hi,In above code subclass Dog is able to inherit variable testInt, but it is not able to inherit method doStuff().When i try to compile above code i am getting error at doStuff() method call.Can you please explain what is difference between variable and method here.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

doStuff() method is inherited. You tried to invoke dostuff() method, not doStuff() method. Java is Case sensitive...

Regards,
Hari Krishna
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, remember that although static methods are inherited, they cannot be overridden. (See Overriding vs. Hiding.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic