| 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: 11
|
|
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.)
|
 |
 |
|
|
subject: Static Doubt
|
|
|