aspose file tools*
The moose likes Beginning Java and the fly likes problem with static method.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with static method.." Watch "problem with static method.." New topic
Author

problem with static method..

Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
Here's a piece of code i tried but couldn't get the reason for the output..

Output is :

How could class B access the static method of class A?Is it a form of hiding?If yes,then what kind of ?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

because anything that is a 'B' IS-AN 'A'.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
A very similar question came up recently at the end of this thread.

It is a bit like hiding, yes, only in reverse. The show() method belongs to class A and class B doesn't actually have a show() method. There is only a show() method in A so that is what the compiler will have gone for.
Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
Thanks Campbell but y doesn't the compiler flag this as an error?
As we all know,static method belongs to a class.In this case it belongs to class A,then how can we access it using the subclass(B)?
And to be honest, i din get fred....

anything that is a 'B' IS-AN 'A'.


i guess here i m talking about something which belongs to A,so it might not belong to B.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
Rules of inheritance: if "B extends A" then a "B" is-a[n] "A." We say inheritance implies an "IS-A" relationship.

The features of "A" (exception constructors) are repeated in "B."

Imaging you have Vehicle which is extended by Car. Then a Car IS-A Vehicle, and any features of Vehicle can reappear in Car.
Max White
Ranch Hand

Joined: Jun 28, 2008
Posts: 85
Thanks,i got it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39788
    
  28
Originally posted by Max White:
Thanks,i got it.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with static method..