File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static Doubt" Watch "Static Doubt" New topic
Author

Static Doubt

maredu ramesh
Greenhorn

Joined: Sep 14, 2007
Posts: 4


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.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Chandrasekhar Mangipudi
Ranch Hand

Joined: Jan 29, 2006
Posts: 118
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.


Thanks & Regards,
ChandraSekharMangipudi
maredu ramesh
Greenhorn

Joined: Sep 14, 2007
Posts: 4


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.
Hari Krishna
Greenhorn

Joined: Nov 28, 2006
Posts: 12
Hi,

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

Regards,
Hari Krishna


SCJP 93%<br />SCWCD 86%<br />SCBCD 92%<br />SCDJWS 95%
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Also, remember that although static methods are inherited, they cannot be overridden. (See Overriding vs. Hiding.)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Static Doubt
 
Similar Threads
Are static variables inherited?
Static Confusing
is the static variable available to subclass
Moc Qes on Static var ,chap 2.
Doubt in Constructor